Notes Chapter 13

advertisement
Notes Chapter 13
Exercise 1
insheet using
http://mysite.avemaria.edu/gmartinez/Courses/ECON230/data/houst.txt,
clear
o These are Housing Starts: Total: New Privately Owned Housing Units Started
(Seasonally Adjusted Annual Rate)
 from the Federal Reserve Bank of St. Louis Economic Research Data Base
 http://research.stlouisfed.org/fred2/series/HOUST
o br
 notice the variable date is a string (text), not numbers. So let’s generate a
new variable with the dates
o gen time=_n
o br time
 this variable is just 1, 2, 3, etc.
o format time %tm
 this formats it as a “time” variable, in months. Month 0 = January 1960.
Month -10 is March 1959; month 10 is November 1960 (weird, isn’t it?).
o br time date
 We need to move all the time numbers down so they start at January 1959
instead of February 1960. That’s a year earlier, and a month.
o display 1*12+1
o replace time = time-13
o br time date
o tsset time
 This (“time series set”) tells Stata that time is, well, a time variable. This
saves us a few keystrokes.
o tsline houst
o Pattern?
 Trend?
 Seasonal Variation?
 Economic Cycles?
 Irregular?
Exercise 2
insheet using
http://mysite.avemaria.edu/gmartinez/Courses/ECON230/data/paynsa.txt,
clear
o These are Total Nonfarm Payrolls: All Employees (Not Seasonally Adjusted)
 from the Federal Reserve Bank of St. Louis Economic Research Data Base
 http://research.stlouisfed.org/fred2/series/HOUST
o br
o gen time=_n
o format time %tm
o br time date
 time starts in January 1939, 21 years and a month before February 1960
o display 21*12+1
o replace time = time-253
o
o
o
o
br time date
tsset time
tsline paynsa
Pattern?
 Trend?
 Seasonal Variation?
 Irregular?
Trends and Seasons



reg paynsa time
o write down the estimated regression equation
̂ = _________ + _______𝑡𝑖𝑚𝑒
𝑃𝐴𝑌𝑁𝑆𝐴
predict trend
tsline paynsa || tsline trend
A Seasonal Dummy Variable
 gen month=((_n)/12-int((_n)/12))*12
 br month
 replace month=12 if month==0
 br month
 xi: reg paynsa time i.month
o this runs a regression of PAYNSA on time and month, where month is an indicator
variable.
 br _Imonth*
o It would NOT be good to just run
reg paynsa time month
because STATA would think that month supposed to be quantitative, and that June
(month 6) is somehow three times larger than February (month 2). You need to tell
STATA that this is an indicator variable, and the “xi … i.” syntax does that.
 In some cases, it may make sense to ask whether the “x” has a different effect
on “y” at different times of the year (or for different values of the dummy
variable). Then what you do is “interact” the quantitative and indicator
variables. Look at the help file for xi for more information.
o The coefficients on _I compare the impact of the month of, say, March, against the
impact of January. What months are different from January, statistically speaking?
Seasonal Adjustment
 gen sf = paynsa/trend
 tabstat sf, by(month)
 gen sf_adj = .
 replace sf_adj=0.9861306 if month==1
 replace sf_adj=0.9867711 if month==2
 replace sf_adj=0.9915493 if month==3
 replace sf_adj=0.9968099 if month==4
 replace sf_adj=1.001335 if month==5
 replace sf_adj=1.007217 if month==6
 replace sf_adj=0.9986323 if month==7










replace sf_adj=1.0008 if month==8
replace sf_adj=1.00581 if month==9
replace sf_adj=1.007368 if month==10
replace sf_adj=1.007376 if month==11
replace sf_adj=1.010397 if month==12
tabstat sf sf_adj, by(month)
scatter sf_adj month in 1/12, connect(direct) lpattern(solid)
yline(1) mcolor(maroon)
gen paysa =paynsa/sf_adj
tsline paynsa paysa
tsline paynsa paysa in 500/599
Autocorrelation
 reg paysa time
 rvfplot
 predict paysant, r
 tsline paysant
 scatter paysant L.paysant
o L.residual is the residual from the previous period. For the Linear Regression
model to work properly, residuals should be uncorrelated with previous-period
residuals.
 reg paysant L.paysant
 predict residual, r
 scatter residual L.residual
Moving Average and Exponential Smoothing Models
 tssmooth ma paysmooth=paysant, window(12 1 12) replace
 tsline paysant paysmooth


tssmooth exp paysmoothexp=paysant, parm(.1) replace
tsline paysant paysmoothexp
Exponential regression
 gen logpaynsa = log(paynsa)
 reg logpaynsa time
o write down the estimated regression equation
̂ = _________𝑒 _______𝑡𝑖𝑚𝑒
𝑃𝐴𝑌𝑁𝑆𝐴







predict logtrend
gen levellogtrend=exp( logtrend)
tsline paynsa || tsline levellogtrend
graph rename log
tsline paynsa || tsline trend
graph rename linear
graph combine linear log, cols(2)
Download