I am learning STATA programming. The following
question seems very basic, but I wasted much time
debugging it and failed to get through.
I copied the following codes exactly from somewhere,
but I can not get it running in STATA 8.1. What's the
problem?
Here is a working version. Note that you need _b[_cons], and the
program must be rclass:
capt program drop _all
set seed 10101
program define simrandm, rclass
version 8.2
if "`1'"=="?" {
global S_1 "b_const se_const b_slope se_usual se_white"
exit
}
drop _all
set obs 20
gen x = invnorm(uniform())
gen u = x*invnorm(uniform())
gen y = 1+1*x + u
regress y x, robust
scalar sewhite=_se[x]
regress y x
return scalar a= _b[_cons]
return scalar as= _se[_cons]
return scalar b= _b[x]
return scalar sb= _se[x]
return scalar sw= sewhite
end
simulate "simrandm" a=r(a) as=r(as) b=r(b) bs=r(sb) bw=r(sw), reps(1000)