I estimate a spatial regression model and then I calculate the marginal impact of the regressor on the dependent variable. Since I use a spatial lag model, I have a direct, an indirect and a total impact. Now, for each county in my dataset, I would like to estimate the indirect impact and to save it in a separate column.
Specifically, I use the datasets homicide1990 and homicide1990_shp available through the example datasets in Stata. Then, I use:
Code:
spmatrix create idistance " /* I create an inverse distance matrix */ spregress hrate unemployment, dvarlag(W) het gs2sls /* I estimate a spatial lag model */
Code:
estat impact
each county
in the data and save them in a new column. So I type:
Code:
gen coefficients = . local i = 1 local id "876 921 966 994" /* This numbers identify the first four counties in the dataset */ foreach s of local id{ estat impact if _ID==`s' mat r`s' = r(b_indirect) replace coefficients = r`s'[1,1] in `i' }
Thanks in advance
0 Response to Saving coefficients in a column
Post a Comment