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?
Multi-response variablesHello, I would like to calculate how the overall prevalence rates of different health conditions ha…
RDD with categorical outcome variableI am just wondering if there is anyone out there able to perform rdrobust with categorical outcome v…
Panel data dummyDear all, I have a question regarding my research into the influence of political factors on econom…
Regression results: omitted standard errors and other statisticsHi Everyone, I am trying to estimate the impact of a policy on an outcome that contains 17% zeros (…
Mixed Models - considering time in the interaction term (timepoint##intervention) as continuous or dummyDear Statlisters, I am analysing the data from an medical intervention in a pilot study with 29 ind…
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