*STATA TUTORIAL: MICROECONOMETRICS *The objective of this do file is to show you how to use a do file for you analysis. *It will also contain some commands we will oversee during the lecture so that you can use them later. *Please keep a copy of this do file and the slides in your H drives for future reference. *A1 *********************** *Starting a do file clear *clear deletes any previous datasets, variables, etc. that are in the current memory set mem 50m *This tells the computer how much memory to allocate to stata. You will get an error messageif memory is insufficient capture log close *This tells stata to close a log file if it is open (a file that records all output from your stat session) *In general you will download your data using commands such as: * use "C:\database.dta" * insheet using "C:\database.csv" *For the tutorial I will instead generate a dataset so that you can run some commands. set obs 1000 *This tells stata the database will have 1000 observations *Slide: Dates in Stata are numbers *For the time series example: gen datevar=_n format datevar %td *browse format datevar %tm *browse tsset datevar *Slide: What if date comes in two variables: clear set obs 1000 gen month=_n gen year=_n+30 *Slide: Dickey Fuller gen y=uniform()*100 *Note: this is iid variable: should have no unit root tsset month dfuller y *We reject the unit root hypothesis drop y gen x=uniform()*100 gen y=300*_n+uniform()*100 dfuller y *We detected a unit root *Slide: Cointegration gen z=0.8*y+uniform()*100 dfuller y dfuller z reg z y predict res, r dfuller res *Slide fixed effects: clear set obs 1000 gen x1=invnorm(uniform())*100 *Our x1 variable is normal distributed with mean 0 and sd 100 gen x2=invnorm(uniform())*100 *Our x2 variable is normal distributed with mean 0 and sd 100 gen alfa=int(_n/10)*100 *This is the fixed effect. Every 10 observations share the same alfa *Note that alfa is uncorrelated with x1 or x2 this will be important below gen year= mod(_n,10) gen y=3*x1+5*x2+alfa+80*year+invnorm(uniform())*150 *This is the true relationship between y and the x's plus some normal iid noise *Traditional (cross section) regression in Stata: reg y x1 x2, r *********************** *Fixed effects regression using xtreg: xtset alfa year xtreg y x1 x2 ,fe r