Hi, I am trying to save beta coefficients, constant and residuals and need advice if the following procedure returns the correct values.
Problem and cohort description: I am studying a disease outcome (lsf), over time (measure_disease_exam_duration) among a cohort of individuals (personal identification=pnr). I would like to make a regression model for each patient (pnr) and save the beta coefficient, constant and residual for each of the resulting model/patient. I have searched and tried some code examples, but have not been able to get them to work. I did manage to get the code below to work, but I am uncertain if the code returns the correct values.
*********************
*Stata 13.1
*Saving residual
sort pnr examdate
set more off
levelsof pnr, local(pnr)
gen residual_lsf = .
tempvar temp
foreach y of local pnr {
regress lsf measure_disease_exam_duration if pnr == `"`y'"'
predict `temp', resid
replace residual_lsf = `temp' if pnr == `"`y'"'
drop `temp'
}
*Saving coefficients and constants
sort pnr examdate
set more off
levelsof pnr, local(pnr)
gen lsf_beta = .
gen lsf_constant = .
tempvar beta1
foreach y of local pnr {
regress lsf measure_disease_exam_duration if pnr == `"`y'"'
replace lsf_constant = _b[_cons] if pnr == `"`y'"'
replace lsf_beta = _b[measure_disease_exam_duration] if pnr == `"`y'"'
}
Related Posts with Saving beta coefficients, constant and residuals from linear regression models? Is this code correct?
Ordered Probit vs Random Effect Ordered Probit for Panel DataDear all, I am currently working with a dataset involving firms credit ratings (dependent variable)…
test Code: . xtnbreg collab_weight lie_dummy lmie_dummy umie_dummy hie_dummy crudeoil distance exp_good…
Multilevel Models and DHS DataHello, I am trying to fit a multilevel model examining HIV risk behaviors among those living with H…
Measuring women's empowerment: creating an index for psychological well being, social support and decision-making powerDear Statalisters, For my thesis I am working on a dataset in which empowerment is measured from th…
MULTILEVEL – Mixed Effects Model Specification with Random Intercept and SlopesDear STATA colleagues, I am working with data containing approximately 300 000 individuals, grouped…
Subscribe to:
Post Comments (Atom)
0 Response to Saving beta coefficients, constant and residuals from linear regression models? Is this code correct?
Post a Comment