質問

I have a following code where I am trying to replicate the estimation for n times and then generating prediction and coefficients for further use.

capture program drop mypro
program define mypro
drop _all
sysuse auto
bsample
reg mpg price headroom
mat mycoef=e(b)
gen mypri=mycoef[1,1]
gen myhead=mycoef[1,2]
gen mycons=mycoef[1,3]
predict x1b
end
simulate, seed(10) reps(10) nodots : mypro

The simulate by default gives only the coefficients from 10 different samples. However, I am trying to save each sample dataset along with coefficients mpri, myhead, myconst,and x1b . Is it possible to do this using simulate or do I need to use loop?

Updated as per comment of Nick:

capture program drop mypro
program define mypro
set seed 1
local r=10
forvalues i=1/`r'{
drop _all
sysuse auto
bsample
reg mpg price headroom
mat mycoef=e(b)
gen mypri=mycoef[1,1]
gen myhead=mycoef[1,3]
predict x1b
save data`i',replace
}
end
役に立ちましたか?

解決

You are calling simulate to run your program to take a bootstrap sample to get regression results.

  sysuse auto
  bootstrap : reg mpg price headroom 

is a much simpler approach. Look at the documentation for bootstrap to learn more.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top