آکادمیا کافه
راهنما و آموزش نرم افزار STATA - نسخه قابل چاپ

+- آکادمیا کافه (https://www.academiacafe.com/pf)
+-- انجمن: نرم‌افزارها (https://www.academiacafe.com/pf/Forum-%D9%86%D8%B1%D9%85%E2%80%8C%D8%A7%D9%81%D8%B2%D8%A7%D8%B1%D9%87%D8%A7)
+--- انجمن: راهنمای نرم‌افزارهای تخصصی (https://www.academiacafe.com/pf/Forum-%D8%B1%D8%A7%D9%87%D9%86%D9%85%D8%A7%DB%8C-%D9%86%D8%B1%D9%85%E2%80%8C%D8%A7%D9%81%D8%B2%D8%A7%D8%B1%D9%87%D8%A7%DB%8C-%D8%AA%D8%AE%D8%B5%D8%B5%DB%8C)
+--- موضوع: راهنما و آموزش نرم افزار STATA (/Thread-%D8%B1%D8%A7%D9%87%D9%86%D9%85%D8%A7-%D9%88-%D8%A2%D9%85%D9%88%D8%B2%D8%B4-%D9%86%D8%B1%D9%85-%D8%A7%D9%81%D8%B2%D8%A7%D8%B1-STATA)

صفحات 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17


RE: استاتا - yalda5 - 23-12-2015

(22-12-2015, 12:58 PM)es.karimi نوشته: سلام وقتی داده هامو تو استاتا پیست میکنم کلیه داده ها قرمز رنگن فقط سال ها مخفف متغییرها و اعداد کشورها سیاهن مشکل چیه؟

سلام دوست عزیز؛ داده هاتون رو تو اکسل به این ترتیب مرتب کنید ، ستون اول : سال، ستون دوم: کشور، ستون سوم: متغیر وابسته و ستون های بعدی متغیرهای توضیحی و کنترل ،
بعد از آماده کردن داده ها میتونید از این جدولی که درست کردین، کپی بگیرین و در داخل قسمت editor استاتا past کنید.


RE: راهنما و آموزش نرم افزار STATA - saeede_ec - 13-01-2016

سلام بر دوستان گرامی، من یک سری کد دارم اما نمی دونم چطوری اجراشون کنم ممنون میشم بهم کمک کنید: کدها مربوط به مدل pvar است.
**  pvar.ado - package for estimating VAR  (vector auto-regressions)
**
** created by Inessa Love (Chevtchinskaia), March 2000, contact: ilove@worldbank.org
**
** THIS IS SET UP TO DO PANEL DATA VAR (see notes below) 
**
** use of this package requires program sgmm.ado (enclosed with the package)
** or, you can use your own system estimation program , but the estimates 
** must be in the same format as after my sgmm.ado  
** 
** SYNTAX : 
** 
** pvar varlist [if exp], [lag(p) options]
** 
** where: varlist  is the list with variable names in desired order (order is important!)
**        p is optional number of lags in VAR, must be integer >0 (default=1) 
**        if is optional subsample indicator (using standard Stata's syntax)
**
** options are (must be low case):
**
** gmm  -  will estimate coefficients by gmm (this will call a separate program sgmm.ado)
**        required option if new model is estimated (even if only the order changed!), 
**        otherwise the latest estimates are taken from the memory (left after previous run of 
**        the program);  gmm must be the first parameter for a new model; 
**
** impulse - will generate numerical impulse-responses without errors
**   list_imp - will list a table with impulse-responses (use after impulse)
**   gr_imp -  will graph impulses (witout errors ); if using monte for standard errors - no 
**           need to graph impulses separately
**
** monte [#] - will generate errors for impulse responses using monte-carlo simulation;
**         optional parameter after monte is desired number of repetitions, default 200;
**         note that monte will call impulse - so no need to specify it separately;
**         monte will graph impulses with the bands automatically; 
**   list_mon - will list tables with impulses and error bands (use after monte)
**
** decomp - will print out variance-decompositions; one optional parameter is the max number
**          of periods (note that ony every 10th period is printed out), default is 20
**          to use different number of periods have to use double quotes for ex. "decomp 30"
** 
** for example, the common line to call the program would look like :
**
** pvar IK SK , lag(3) gmm impulse monte 500 decomp
**
** here number 500 (repetitions for monte-carlo) could be ommited (or changed)
** if errors on impulses are not needed, change monte for gr_imp (to graph without errors)
**
** Notes : 
**
** 1) this will do panel data VAR! that is it assumes that fixed effects are removed
** using helmert transformation and transformed variables already exist in the dataset with 
** names h_y1, h_y2 ...( where y1 and y2 - are original names of the variables);
** it is advised that original variables are timedemeaned before helmert (for panel only);
** note that names in the startup line are original names, (i.e. if IK is original - variable 
** and h_IK is helmert transformed use IK and not h_IK in the startup line ! ;
** helmert transformation program is included with the package (or use your own) ;
** estimation is by gmm with untransformed variables used as instruments for helmert-
** transformed
** 2) to use different transformation (for ex. first difference) - the easiest way is to fool 
** the program and store transformed variables with names h_y1 h_y2 ...
** 3)  Alternatively, to use this program without fixed effects -  create a copy of original 
** variables  with names h_y1 h_y2... (the program will use original variables as both 
** regressors and instruments i.e. use gmm program to perform system OLS)
** 4) no constant is included at this time! (since var's are demeaned and helmert)
** 5) to run any of enclosed programs outside of var.ado - need to create separate ado 
** files -i.e. copy program impulse into impulse.ado and so on
** 6) formulas are from Hamilton 1994 ch.11
** 7) Maximum number of variables is 6 at this time (to extend it change routine MAKED to add 
**    D7... matrices 
** 8) before you can run these you must do the command tsset to tell Stata what is your panel data structure,
**   for example if your cross-section variable is named id and yur itme variable is named year 
**   do the command: tsset id year
**   also note that if you are using my program helm.ado your i and t variables must be named id and year
**
** The programs work to the best of my knowledge and ability, but please  - Use at your own risk ! 
** Please report all errors or modifications that you make to ilove@worldbank.org 
**
**


capture program drop pvar
program define pvar
version 6.0
set matsize 200
set log l 100

syntax varlist [if] , [ Lag(integer 1) ] [ * ]

*di " number of lags entered is |`lag'|"
*di " remaining options are stored as |`options'|"
*di " IF is set to |`if'|"


global P=`lag'

preserve        
if "`if'"~="" { keep `if' }      /* if a subset of the data was specified */
global if="`if'"

***** separating options into local macros **************
tokenize `options' , parse(" """)   /* this will take options into separate macro arguments */
  local i=0        
  while "`1'"~="" {  
     * di "current option read is `1'" 
     local i=`i'+1
     local parm`i' "`1'"   /* assign the entered parameter to local macro parm1, parm2 ... */
     mac shift              
     }
  local parms `i'

if `parms'==0 { 
   di in red "at least one option is required"
   exit }



***** creating global lists Y, X, Z to call GMM **********************
tokenize `varlist'

local g=0        /* g is a counter of equations for GMM/variables in VAR */
global names=""
while "`1'"~="" {          /* read one input variable at a time */
   local g=`g'+1
   *drop if `1'==.             /* drop MISSING - OPTIONAL - uncomment  */ 
   global y`g'="h_`1'"        /* these will be Y1...YG to use in GMM */
   global name`g'="`1'"       /* this is a list of original names one by one */
   global names="$names `1'"  /* this is global list of all names */
   local p=1                  /* p is counter for lags */
   while `p'<=$P {            /* will generate x's and z'a for each lag */
     local x_`p' "`x_`p'' l`p'.h_`1'" 
     local z_`p' "`z_`p'' l`p'.`1'"
     local p=`p'+1 
     }
mac shift

global G=`g'                /* total number of variables/equations */


** make x's and z's lists from separate lags:
local p=1   
while `p'<=$P {             /* join together separate lags */
   local x "`x' `x_`p''" 
   local z "`z' `z_`p''"
   local p=`p'+1 
   }
** now make all Xg and Zg to be the same as x and z - i.e. use same insstruments for each eq.
local g=1
while `g'<=$G {
global x`g' "`x'"
global z`g' "`z'"
*helm ${name`g'}   /** optional is to call HELMERT HERE - after missing have been deleted **/
  local g=`g'+1 
}

*di " G= $G"
*di " y1=$y1, y2=$y2, x1=$x1, x2=$x2, z1=$z1, z2=$z2"
*di "$names"


** calling the routines that were requested  - OPTIONS after comma
local g=1  
if "`parms'"~="" {     
while `g'<=`parms' { 

if "`parm`g''"=="monte" {     /* this will allow for a number of iterations to be entered*/ 
    local temp=`g'+1 
    capture confirm integer number `parm`temp''   /* check if next parameter is integer */
    if _rc==0 {                            /* yes, it is integer */
         local g=`g'+1                     /* skip to the next parameter */
         monte `parm`temp''                /* call monte with parameter */
         }
       else { monte }                    /* otherwise call monte without parameter */
    local g=`g'+1
    } 
else {
  if "`parm`g''"=="gmm"  { sgmm }  /* renamed gmm into system gmm */
  else {`parm`g'' }
  local g=`g'+1
   }
}
}

end

*************************************************
** Monte-Carlo for errors on impulse-responses **
*************************************************
capture program drop monte
program define monte
** will perform Monte-Carlo simulation for errors, parameter 1 has the number of
** repetitions, default 200
set matsize 800
impulse                         /* call  impulse - for the first pass */
if "`1'"==""{ global maxi 200}  /* number of iterations for MOnte-Carlo, default 200 */
 else global maxi `1'  

*** 1 generate E - sigma, var-cov matrix of errors uu
** Dn and Dnp used to transfrom vec into vech and back
maked $G               /* get appropriate matrix Dn corresponding to number of equations G */
mat Dnp=(inv(Dn'*Dn) )*Dn'
vec uu vecu
mat vechu=Dnp* vecu
mat E=(1/$T)*2*Dnp*(uu # uu)*Dnp'  /* var-cov of elements of uu */
                         /* ask Charlie about T - degrees of freedom */

drop _all
use impulse
drop varname
qui save errors, replace   /* start with empty dataset */

di "Starting Monte-Carlo loop : $S_TIME , total $maxi repetitions requested"
set more off 
capture mat drop Di   /* this is big matrix containing impulses */

** loop around here :
global i = 1   /* number of iterations to use in impulse program */
while $i<=$maxi { 
***  generate random vectors for coefficients and uu
random bgmm var     /* random vector with coefficients, mean: bgmm var: var */
mat bgmmi=random
random vechu E      /* random vector vech with errors, mean: vecu, var: E*/
mat vecui=Dn*random    /* random vector vec with errors */
unvec vecui uui        /* uui is the random matrix with errors */
  mat rownames uui= $names
  mat colnames uui= $names

*comp i           /* generate companion matrix for simulation i -will be called from impulse*/
impulse 6 i
global i=$i+1 
}

di "finished Monte-Carlo loop : $S_TIME "


** create percentiles and merge with impulse data
local g = 1
while `g'<=$G { /* creating names of new variables for collapse */
  local list1 "`list1' ${name`g'}_5=${name`g'}"
  local list2 "`list2' ${name`g'}_95=${name`g'}"
  local g=`g'+1 }
*di "list1 `list1' list2 `list2'"


collapse (p5) `list1' (p95) `list2', by(order s)
sort order s
merge order s using impulse
qui save imp_$maxi,replace
gr_imp i
end

**
** this will graph impulses with monte-errors - it is done autumatically in monte ! ***
**
capture program drop gr_mon
program define gr_mon
 drop _all
 use imp_$maxi
 gr_imp i
end

*********************************
** graph of impulse-responses ***
*********************************

capture program drop gr_imp
program define gr_imp

* can graph with errors and without errors

if "`1'"=="i"{local i "i"}   /* in case of Monte-Carlo `i'="i" */
  else local i ""            /* normal case `i'is a blank     */

set textsize 170

local g=1
while `g'<=$G {         /* row variable - the one that is recepient of respone */

  local j=1
  while `j'<=$G {      /* column variable - the one causing response */
     if "`i'"=="i" {   /* with errors */
       format ${name`j'}_5 ${name`j'} ${name`j'}_95 %7.4f
       gr ${name`j'}_5 ${name`j'} ${name`j'}_95 s if /*         */ varname=="${name`g'}",saving(gr`g'_`j',replace) s(iii) c(lll) yli(0) /*                               
        */  b1("response of ${name`g'} to ${name`j'} shock") 
        }
     else {             /* without errors */
        format ${name`j'} %7.4f
        gr ${name`j'} s if varname=="${name`g'}",saving(gr`g'_`j',replace) s(i) c(l) yli(0) /*                               
        */  b1("response of ${name`g'} to ${name`j'} shock") 
        }
     local grlist "`grlist' gr`g'_`j'"   /* list of all graphs to put together */
     local j=`j'+1 
   }
local g=`g'+1 
}

set textsize 100
*if length("   Impulse-responses for $P lag VAR of $names ")>80 { set textsize 90}

if "`i'"=="i"{ 
   local b2="b2(Errors are 5% on each side generated by Monte-Carlo with $maxi reps)"}

if "$if"~="" { local t2="t2(Sample : $if)"}

if length("   Impulse-responses for $P lag VAR of $names ")<80 {
   gr using `grlist', t1(     Impulse-responses for $P lag VAR of $names ) `t2' `b2'
    }
else {
   gr using `grlist', t1( $P lag VAR of $names ) `t2' `b2'
   }
end



*********************************
** Impulse-response functions  **
*********************************
**
** these are responses to 1 std shock, formulas are:
** dXi/Dvj = A^s*P[.,j]   response of variable Xi to shock in variable j at time s
** take jth column of matrix P - cholesky decomposition of u'u
** unit matrix J=[I(GxG),0,0...,0] is used to extract the right portion 
** (first GxG block) of matrix A^s
**
** the data currently in memory will be save in a file temp_data
** impulse-responses will be save in a file impulse.dta 
**
** takes 2 parameters (optional)
** 1 is - maximum number of periods for response, default=6
** 2 = i if it is a Monte-Carlo simulation, note that in this case
**  first parameter must also be nonmissing
**

capture program drop impulse
program define impulse
*set trace on
        

if "`1'"==""{ local bigs 6}  /* number of periods for impulse response */
 else local bigs `1'         /* if parameter is not given, default=6 */   

if "`2'"=="i"{local i "i"}   /* in case of Monte-Carlo `i'="i" */
  else local i ""            /* normal case `i'is a blank     */

comp `i'

capture mat drop D        /* drop only in  a normal case, keep for MOnte-carlo */
matrix P=cholesky(uu`i')
global R=$P*$G               /* R is the dimension of the companion matrix #lags * #vars */
if $P>1 {mat J=I($G), J($G, $R-$G,0) } /* J matrix used to extract nesessary portion of A */
   else mat J=I($G)           /* if P=1 - one lag VAR, J==I - no need to extract anything */

order_           /* will return vector with order */
mat colnames order="order"
drop _all

if "`i'"=="i" {
        mat repeat=J(rowsof(order),1,$i)    /* the repetition number ofr MOnte-Carlo */
        mat colnames repeat="repeat"
        local rep "repeat,"}                /* this will add the number of the repetition for Monte only */
  else   local rep ""


mat AS=I($R)                 /* start with identity matrix - before the first product */

**** Creating impulses for each time s *******************

local s=0                 /* start with time zero AS=I */
while `s'<=`bigs' {       /* time s shock */
  tempname time DS
  mat `time'=J($G,1,`s')   /* will store time for graphing time==s */
  mat rownames `time'= $names
  mat colnames `time'= s

mat `DS' =J * AS * J'* P  /* one step creating impulses for all variables */

mat `DS'= `rep' `time',order, `DS'  /* add column of S - what time the shock is for */
mat D`i'=nullmat(D`i') \ `DS'  /* D is for all times all shocks */
mat AS=AS*A`i'           /* raise A to the power S for next round */
*mat list `DS'           /* i is for MOnte-Carlo, otherwise i=""   */

local s=`s'+1 
}

*mat list D

*drop order


if "`i'"=="i" {              /* for Monte-Carlo save in the errors dataset */
  local gs=(`bigs'+1)*$G     /* this is total number of new variables that will be created */
  local times=int(800/`gs')  /* number of times before saving errors to the disk */
  if $i/`times'==int($i/`times') | $i==$maxi { 
     /* only save every `times' times or at the end, otherwise -accumulate, to save time */
     di "i=$i, " _c
     qui svmat Di, name(col)   /* create variables for graphing/presentation */
     mat drop Di 
     append using errors
     qui save errors, replace
   }
}
else { 
  qui svmat D , name(col)   /* create variables for graphing/presentation */
  qui gen str6 varname=""  /* generate variable with names - for original impulses */
  local i = 1
  while `i'<=$G {
    qui replace varname="${name`i'}" if order==`i' 
     format ${name`i'} %7.4f
    local i=`i'+1 }
  order varname    /* put varname first variable -for printing*/
  sort order s

  qui save impulse, replace 
}

** variables show effect of column variable name on a row variable name
** i.e. column named Q contains effect of Q shock on variable names in varname
** for ex :
** s  varname  x1      
** 1  x1       1
** 1  x2       2     i.e. effect of x1 on x2 in period s=1 is equal to 2 
** 1  x3       3
** this is the best way to organize impulse-responses for graphing
** to graph :
**  gr ik s, by(varname) R c(l) sort ti(reponse to the shock in ik)
**  gr ik s if varname==Q, c(l) sort ti(reponse of Q to the shock in ik)

end


***********
** list  **
***********
** this program will list numbers for impulse-responses without bands  **
capture program drop list_imp
program define list_imp
  drop _all
  use impulse
  di "Impulse-responses of variable in varname to the shock in column variable"
  list  ,nod noobs
end

** this program will list impulsee with errors - one by one **
capture program drop list_mon
program define list_mon
  drop _all
  use imp_$maxi
  local j=1
  while `j'<=$G {      /* column variable - the one causing response */
     di "Impulse-responses of variable in varname to the shock in ${name`j'} "
     format ${name`j'}_5 ${name`j'} ${name`j'}_95 %7.4f
     list varname s ${name`j'}_5 ${name`j'} ${name`j'}_95 , nod
     local j=`j'+1 
  }
end



RE: راهنما و آموزش نرم افزار STATA - موسوی خالدی - 21-01-2016

باسلام برای تخمین مدل(1,1)VAR -MGARCH با  داده های پنل در نرم افزار استاتا باید چه کار کنم؟؟؟؟؟ خواهش میکنم راهنمایی کنید!!!!!!!!


RE: راهنما و آموزش نرم افزار STATA - mona - 22-01-2016

(21-01-2016, 09:15 PM)موسوی خالدی نوشته: باسلام برای تخمین مدل(1,1)VAR -MGARCH با  داده های پنل در نرم افزار استاتا باید چه کار کنم؟؟؟؟؟ خواهش میکنم راهنمایی کنید!!!!!!!!

با سلام ،

برای کدهای var و mgarch میتوانید از فایل های موجود در پیوست استفاده نمایید . ترکیب این دو کد کاری تخصصی است که بعد از مطالعه دو منبع موجود در پیوست میتوانید از مقالات مشابه موضوع شما ( با سرچ کردن در گوگل) استفاده نمایید . اما قدم اول این است که شما با کدهای هر یک از این مدل ها آشنا شوید .

موفق باشید


RE: راهنما و آموزش نرم افزار STATA - melika_zm68 - 31-01-2016

سلام ممنون از مطالب مفیدی که در اختیار ما گذاشتین.
من 9 منطقه رو در 20 سال میخوام بررسی کنم.با استفاده از آزمون اف لیمر متوجه شدم داده های من پول(pool) میباشد.سوالم اینه که باید چه آزمون هایی انجام بدم؟آزمون ریشه واحد؟هم انباشتگی؟دستور این ها در استتا چیست؟و با استفاده از آزمون نسبت راستنمایی متوجه شدم ناهمسانی واریانس دارم.برای حل مشکل از چه روشی استفاده کنم؟
آیا میتوانم از دستور xtgls در استتا برای رفع مشکل ناهمسانی واریانس استفاده کنم؟


RE: راهنما و آموزش نرم افزار STATA - mona - 31-01-2016

(31-01-2016, 02:32 PM)melika_zm68 نوشته: سلام ممنون از مطالب مفیدی که در اختیار ما گذاشتین.
من 9 منطقه رو در 20 سال میخوام بررسی کنم.با استفاده از آزمون اف لیمر متوجه شدم داده های من پول(pool) میباشد.سوالم اینه که باید چه آزمون هایی انجام بدم؟آزمون ریشه واحد؟هم انباشتگی؟دستور این ها در استتا چیست؟و با استفاده از آزمون نسبت راستنمایی متوجه شدم ناهمسانی واریانس دارم.برای حل مشکل از چه روشی استفاده کنم؟
آیا میتوانم از دستور xtgls در استتا برای رفع مشکل ناهمسانی واریانس استفاده کنم؟

با سلام،

تخصص من در داده های pool نیست اما پیشنهاد میکنم از نرم افزار ایویوز استفاده نمایید .

http://www.eviews.com/help/helpintro.html#page/EViews%25209%2520Help%2Fsec_panel.html%23

سایر دوستان هم اگر اطلاعاتی داشته باشند ، در اختیار شما قرار خواهند داد.

موفق باشید


RE: راهنما و آموزش نرم افزار STATA - melika_zm68 - 03-02-2016

سلام
برای آزمون وابستگی مقطعی از چه آزمونی باید استفاده کنم و دستورش تو استا چیست؟
سپاس


RE: راهنما و آموزش نرم افزار STATA - eliroz - 04-02-2016

سلام 
یکی از دوستان عزیز این سوال رو پرسیده بودن و ممکن هست سوالی بقیه دوستان هم باشه:

سلام.خسته نباشید.من تازه برای اولین بار کاربا  نرم افزار استتا را شروع کرده ام. به کمک راهنمایی هایی که تو این سایت شده بود تونستم داده های خودم رو تو استتا وارد کنم.داده های من شامل داده های مصرف بنزین ودرآمد و جمعیت استان های کشور برای سال های 83-93 هست.میخواستم راهنمایی بفرمایید که من چطور میتونم برای داده هام نمودار هیستوگرام بکشم.ممنون میشم اگر لطف بفرمایید ومن رو راهنمایی کنید [عکس: smile.gif] [عکس: smile.gif] 


دوست عزیز شما میتونید از منوی Graphics در نرم افزار استاتا استفاده کنید که آپشن های مختلفی داره. 
میتونید هم دستور هیستوگرام رو اجرا کنید که به صورت زیر هست : 

histogram variable x, frequency
یا 
hist variable x 

استفاده کنید. 
البته همانطور که در بالا گفتم منو Graphics گزینه های متفاوتی داره که میتونید استفاده کنید اما کد هیستوگرام به این صورت هست . می

موفق باشید



RE: راهنما و آموزش نرم افزار STATA - m.zaghi - 09-02-2016

سلام
ببخشید میخواستم بدونم چطور panel var رو تو stata تخمین بزنم؟
از این منبع (2015 -Estimation of Panel Vector Autoregression in Stata: a Package of Programs-Michael R.M. Abrigo and Inessa Love) کد ها رو وارد استتا کردم اما نتونستم حتی یه تخمین ساده انجام بدم؟ خواهش میکنم راهنماییم کنید.ممنون میشم


RE: راهنما و آموزش نرم افزار STATA - افسانه افسانه - 10-02-2016

سلام
من تو استتا تازه کارم. دارم مدل پنل کار می کنم
داده هارو از اکسل وارد کردم.اولا که ستون کشورها همه قرمزه در ثانی وقتی دستور
xtset country year 
می زنم خطای 109 میده به این صورت :
varlist: countryConfusedtringvariable not allowed
چی کار باید کرد؟ مگه چطوری باید اسم کشورها رو وارد کنم؟