Hi,
I have the following code for a simulation. I need help to conclude it.
set obs 100
gen ut=.
gen vt=.
gen yt=1
generate order=_n
gen zt=1
capture program drop my_model
program define my_model, rclass
replace ut = rnormal(0,1)
replace vt = rnormal(0,1)
replace yt=4+yt[_n-1]+ vt if order!=1
replace zt=2+zt[_n-1]+ ut if order!=1
regress yt zt
return scalar constant = _b[_cons]
return scalar coef = _b[zt]
return scalar t = _b[zt]/_se[zt]
return scalar r2 = e(r2)
exit
end
simulate constant=r(constant) coef=r(coef) t=r(t) r2=r(r2), reps(1000): my_model
How can I record correlation coefficient between y and z for each simulation? Corr gives matrix but I need to record only the correlation coefficient and then take the average of them. Thanks in advance.
Ulas
I have the following code for a simulation. I need help to conclude it.
set obs 100
gen ut=.
gen vt=.
gen yt=1
generate order=_n
gen zt=1
capture program drop my_model
program define my_model, rclass
replace ut = rnormal(0,1)
replace vt = rnormal(0,1)
replace yt=4+yt[_n-1]+ vt if order!=1
replace zt=2+zt[_n-1]+ ut if order!=1
regress yt zt
return scalar constant = _b[_cons]
return scalar coef = _b[zt]
return scalar t = _b[zt]/_se[zt]
return scalar r2 = e(r2)
exit
end
simulate constant=r(constant) coef=r(coef) t=r(t) r2=r(r2), reps(1000): my_model
How can I record correlation coefficient between y and z for each simulation? Corr gives matrix but I need to record only the correlation coefficient and then take the average of them. Thanks in advance.
Ulas
Comment