11.05.2010

Regression coefficient stability over time (in Stata)

If you're estimating a regression model with time series or panel data, you often would like to know if the coefficient you're interested in is changing over time or if its stable for subsamples of the time series or panel.

Here's my simple but handy script that let's you see if your coefficient is stable or changing with a single command.  You specify your multiple regression model (for OLS, but you can change it easily to run a different estimator), which coefficient to examine.  It does a sequence of regressions for a moving window of specified length and stores the changing coefficient, SE and CI (t-test).

For example, the figure at right shows the coefficient from the model

GDP_it = B * cereal_yields_it + e_it

for a panel of all countries estimated for a moving window that covers 3 years at a time.

The description of the code is just commented out in the script and pasted below the fold.

[7/14/2011: A small but important error in the code was fixed. Thanks to Kyle for catching it.]

====================================================


S. HSIANG
SMH2137@COLUMBIA.EDU
10/2010


----


coeff_ts Y X Z [if], Coeff(X) Time(t)  [TWindow() level() figoff end mid]


COEFF_TS estimates a sequence of regressions for time series or panel data.  It uses data within a moving window of specified size and stores a specified coefficient from the model for each sample. It then plots that coefficient over time (with SE and CI) and stores it as a new variable.  Unless "end" or "mid" options are specified, the coefficients are associated with the first observation in each sample.


Required arguments:


varlist - specify the linear model as you would for the command "regress"
coeff() - specify which coefficient (independant variable) to plot and store
time() - specify the time variable


Options:


twindow() - specify the number of observations you want to include in each regression [default is 3], if using a panel model, there will be n*twindow() 


observations in each regression
level() - level for the displayed confidence intervals [default is .05]


figoff - supresses the plot (only the coeffs and CIs are stored as new vars)


end - record the coeffs (SE and CI also) with the last observation in each sample [default is first obs]


mid - record the coeffs with the middle obs in each sample [overides end if both mid and end are specified]


Examples:


coeff_ts Y X if year < 2000, c(X) t(year) tw(10)


coeff_ts Y L.Y X Z W , c(Z) t(year) level(.1) end figoff


======================================================

No comments:

Post a Comment