Bookmark and Share

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   Tim Evans <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: Using local(levels) to populate a new variable following parmest
Date   Mon, 14 May 2012 16:24:20 +0100

Nick, Roger,

Thank you for your replies. 

Nick, thank you for tidying my code up - the destring is a hangover from some of my earlier attempts at coding and not yet been tidied up. 

After confusing myself as to exactly where I need to insert the code you suggested to create the new variable, I have it in the right place and working now!

Roger, I like your suggestion, although for what I am after at the moment, I've spent quite some time developing the code using the practice I currently use, so I'm going to bear the parmby for a later day.!

Best wishes

Tim

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Roger B. Newson
Sent: 14 May 2012 16:08
To: [email protected]
Subject: Re: st: Using local(levels) to populate a new variable following parmest

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/

_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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index