Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: Using local(levels) to populate a new variable following parmest
From
Tim Evans <[email protected]>
To
"'[email protected]'" <[email protected]>
Subject
st: Using local(levels) to populate a new variable following parmest
Date
Mon, 14 May 2012 15:21:50 +0100
Hi all,
I'm using Stata 11 and carrying out a series of Cox regressions for which I save the results into a .dta file using -parmest-. I run the regressions on each level contained within a variable (ICD10) using local levels. What I am trying to do is generate a new variable following parmest, which is equal to the local level for which the regression has just been calculated i.e. before I save the file at the end and run through the next level of ICD10, I want to generate a column that holds the value for the first level of ICD10 and so on in subsequent regressions.
Here is my code:
levelsof ICD10, local(levels)
foreach l of local levels {
di as text "_______________________________"
di as text "`l'"
cap noi: xi: stcox delay2v2 `covariates' if ICD10 =="`l'", nolog
preserve
foreach v in delay2v2 { // continuous variables
local l`v' : variable label `v'
if `"`l`v''"' == "" { // if no variable label
local l`v' "`v'"
}
}
parmest, norestore eform
foreach v in delay2v2 {
replace parm = "`l`v''" if parm == "`v'"
}
replace parm = "baseline odds" if parm == "_cons"
**Remeove baseline odds
drop if parm =="baseline odds"
gen label2=""
destring label2, replace
**delay group
replace label2 = 101 if parm == "delay2v2"
label values label2 label2
gen flag=""
destring flag, replace
replace flag = 1 if p<0.05
replace flag = 0 if p>=0.05
label define flag 0 "Not significant" 1 "Significant"
label values flag flag
********************
NEED TO GENERATE NEW VARIABLE HERE?
*********************
**********************
save "T:\mydocuments\cancer_`l'.dta", replace
restore
}
_DISCLAIMER:
This email and any attachments hereto contains proprietary information, some or all of which may be confidential or legally privileged. It is for the exclusive use of the intended recipient(s) only. If an addressing or transmission error has misdirected this e-mail and you are not the intended recipient(s), please notify the author by replying to this e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail or any attachments, as this may be unlawful.
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/