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?
Data AnalysisHello, I have determined 2 parameters (mean_alpha and mean_delta) using 6 different methods for eac…
Create an indicator of participation in long formatDear Statalisters, I have a dataset in long format, measuring spirometry data on three occasions. I…
How can I get GWR R-square?I ran the following gwr model hoping to get the R-square for each point: gwr migration X1 X2 D1, eas…
What is the difference between tab and tab1, and how to retrieve the number of difference value of variable of interest?Today I seach for the use of -tab- command. I saw the -tab1- command, when I use both of them for th…
censusapi packageHello, I am trying to use the censusapi codes and having issues. At the moment, I am limited to cod…
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