When using the post
command, I get the following error:
post command requires expressions be bound in parenthesis
My program generates a matrix which stores regression coefficients for each simulation, and then uses the post
command to declare as float
and place the output of the matrix in parenthesis (betas).
A sample of the code:
*Priors
set more off
global nmc=10
global l = 4 /* number of lags */
global cnt=150 /* number of countries */
set seed 10101
* Gen empty beta matrix
matrix betas = J(153,$nmc+1,.)
*** THIS IS WHERE MONTECARLO STARTS***
program bootStrapCH5, rclass
tempname sim
postfile `sim' betas using results, replace /* As trial I'll create only the betas matrix for now. */
*postfile `sim' betas alpha_mean b1_mean b2_mean b3_mean b4_mean se_alpha se1 se2 se3 se4 using results, replace
quietly {
forvalues i = 1/$nmc {
* Fixed effects regression.
reg gdp_growth_wb L(1/4).gdp_growth_wb i.id
matrix B1= e(b)
mat li B1
predict g_hat,xb
gen e_hat= gdp_growth_wb - g_hat
*gen flag=e(sample)
* Generate the "wild" errors for the forecasts
gen eta=rnormal()
gen e_star=e_hat*eta
**RECURSION
levelsof id, local(codes)
capture noisily replace y_star= _b[_cons] + _b[L.gdp_growth_wb]*L.y_star + ///
_b[L2.gdp_growth_wb]*L2.y_star + _b[L3.gdp_growth_wb]*L3.y_star + ///
_b[L4.gdp_growth_wb]*L4.y_star + e_star if (id==1 & Dini4forward==1)
forvalues cc= 2(1)150 {
capture noisily replace y_star= _b[_cons] + _b[`cc'.id] + _b[L.gdp_growth_wb]*L.y_star + ///
_b[L2.gdp_growth_wb]*L2.y_star + _b[L3.gdp_growth_wb]*L3.y_star + ///
_b[L4.gdp_growth_wb]*L4.y_star + e_star if (id==`cc' & Dini4forward==1)
}
*Regression with new sample: y_star
reg y_star L(1/4).y_star i.id
matrix b= e(b)'
matrix betas= (betas , b)
matrix list betas
post `sim' float (betas)
}
}
postclose `sim'
end
*Execute program
bootStrapCH5
use results, clear
summarize
I also tried an alternative:
post `sim' (betas)
And got the error:
> type mismatch
post: above message corresponds to expression 1, variable betas
Any ideas on how to fix this are very much appreciated.