Regression coefficient stability over time (in Stata)
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.]
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.
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
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]
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