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   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Using local(levels) to populate a new variable following parmest
Date   Mon, 14 May 2012 15:29:11 +0100

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/


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