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]
Re: st: Using local(levels) to populate a new variable following parmest
From
"Roger B. Newson" <[email protected]>
To
[email protected]
Subject
Re: st: Using local(levels) to populate a new variable following parmest
Date
Mon, 14 May 2012 16:07:59 +0100
You might prefer to use -parmby- instead of -parmest-, if you want to
save the by-variable -ICD10- in the output dataset (or resultsset). As in:
parmby "xi: stcox delay2v2 `covariates'", by(ICD10) norestore eform
which saves -ICD10- in the resultsset, which is then sorted primarily by
-ICD10- and secondarily by the parameter sequence variable -parmseq-.
The -parmby- module is part of the -parmest- package.
I hope this helps.
Best wishes
Roger
Roger B Newson BSc MSc DPhil
Lecturer in Medical Statistics
Respiratory Epidemiology and Public Health Group
National Heart and Lung Institute
Imperial College London
Royal Brompton Campus
Room 33, Emmanuel Kaye Building
1B Manresa Road
London SW3 6LR
UNITED KINGDOM
Tel: +44 (0)20 7352 8121 ext 3381
Fax: +44 (0)20 7351 8322
Email: [email protected]
Web page: http://www.imperial.ac.uk/nhli/r.newson/
Departmental Web page:
http://www1.imperial.ac.uk/medicine/about/divisions/nhli/respiration/popgenetics/reph/
Opinions expressed are those of the author, not of the institution.
On 14/05/2012 15:29, Nick Cox wrote:
gen level = "`l'"
By the way, the code
gen flag=""
destring flag, replace
replace flag = 1 if p<0.05
replace flag = 0 if p>=0.05
seems to boil down to one line
gen flag = p< 0.05
There is no point in creating an empty string variable and then
pushing it through -destring-.
Nick
On Mon, May 14, 2012 at 3:21 PM, Tim Evans<[email protected]> wrote:
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> gen flag=""
destring flag, replace
replace flag = 1 if p<0.05
replace flag = 0 if p>=0.05
**delay group
replace label2 = 101 if parm == "delay2v2"
label values label2 label2
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
}
*
* 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/
*
* 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/