I am trying to store the coefficients from a simulated regression in a variable b1 and b2 in the code below, but I'm not quite sure how to go about this. I've tried using return scalar b1 = _b[x1]
and return scalar b2 = _b[x2]
, from the rclass()
function, but that didn't work. Then I tried using scalar b1 = e(x1)
and scalar b2 = e(x2)
, from the eclass()
function and also wasn't successful.
The goal is to use these stored coefficients to estimate some value (say rhat) and test the standard error of rhat.
Here's my code below:
program montecarlo2, eclass
clear
version 11
drop _all
set obs 20
gen x1 = rchi2(4) - 4
gen x2 = (runiform(1,2) + 3.5)^2
gen u = 0.3*rnormal(0,25) + 0.7*rnormal(0,5)
gen y = 1.3*x1 + 0.7*x2 + 0.5*u
* OLS Model
regress y x1 x2
scalar b1 = e(x1)
scalar b2 = e(x2)
end
I want to do something like,
rhat = b1 + b2, and then test the standard error of rhat.
e(x1)
. Butscalar b1 = _b[x1]
etc. would work either within the program or after it. It is not clear that you need to declare the program eithereclass
orrclass
if all you want to access the coefficient estimates. Off-topic on CV regardless, so I'm voting to migrate to SO. See help in the CV Help Center on software-specific questions. . – Nick Cox