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]

I additionally have 7 other variables a, b, c, d, e, f, g that I would like to add to the original model in all possible combinations ie: original model or a original model or b original model or c original model or d original model or e original model or f original model or g original model or a or b original model or a or c ..... original model or a or b or c original model or a or b or d ..... original model or a or b or c or d or e or f or g I am scratching my head trying to work out how to include this loop within the original loop and would be grateful for any suggestions. Do file so far is: [r12cough and rrate1 are two of the seven additional variables I am adding in combination to the original model and are shown as an example of what I am trying to achieve... but by using a loop] xi:logistic died i.sex1 i.r18unwel_1 i.r21dyspn i.r25whtl i.hiv i.pulse1 *generates a variable p which is the probability of each individual being a case, based on this logistic regression model predict p *generates a variable x which is going to be used as the mortality status based on the model gen x_reg=0 gen y_reg=0 gen x_h=0 gen y_h=0 qui gen n=1 *Creates a loop to do the sens/spec/ppv/npv for cutoffs from 0.005 to 0.650 - incrementing by 0.005 forvalues i=0.005(0.005)0.65 { *resets x to zero within each value of cutoff qui replace x_reg=0 qui replace y_reg=0 qui replace x_h=0 qui replace y_h=0 disp "" disp "" disp "cutoff = " `i' *replaces x=1 if the individual has a probability of being a case which is higher than the cutoff i qui replace x_reg=1 if p>=`i' & p!=. qui replace x_h=1 if (p>=`i' & p!=.) qui replace x_h=0 if p<`i' *add in combinations of additional variables with high specificity qui replace x_h=1 if (p>=`i' & p!=.) | r12cough==1 | rrate1==1 qui replace x_h=0 if p<`i' & r12cough!=1 & rrate1!=1 *tabulates true mortality status (died) against predicted (x) for each cutoff value disp "True vs predicted mortality status based on LR model only" tab died x_reg, row disp "True vs predicted mortality status based on LR model plus r12cough or rrate1" tab died x_h, row qui replace y_reg=1-x_reg qui replace y_h=1-x_h preserve qui collapse (sum) x_reg y_reg x_h y_h n, by(died) qui gen sensspec_reg=x_reg/n if died==1 qui gen sensspec_h=x_h/n if died==1 qui gen id=1 qui replace sensspec_reg=y_reg/n if died!=1 qui replace sensspec_h=y_h/n if died!=1 qui reshape wide sensspec_reg x_reg y_reg sensspec_h x_h y_h n, i(id) j(died) qui gen lr_reg=sensspec_reg1/(1-sensspec_reg0) qui gen ppv_reg=x_reg1/(x_reg0+x_reg1) qui gen npv_reg=y_reg0/(y_reg0+y_reg1) qui gen lr_h=sensspec_reg1/(1-sensspec_h0) qui gen ppv_h=x_h1/(x_h0+x_h1) qui gen npv_h=y_h0/(y_h0+y_h1) disp "Sensitivity based on LR model only = " %5.3f sensspec_reg1 " at cutoff p=" `i' disp "Specificity based on LR model only = " %5.3f sensspec_reg0 " at cutoff p=" `i' disp "Positive predictive value based on LR model only = " %5.3f ppv_reg " at cutoff p=" `i' disp "Negative predictive value based on LR model only = " %5.3f npv_reg " at cutoff p=" `i' disp "Likelihood ratio based on LR model only = " %5.3f lr_reg " at cutoff p=" `i' disp "Sensitivity based on LR model plus r12cough or rrate1= " %5.3f sensspec_h1 " at cutoff p=" `i' disp "Specificity based on LR model plus r12cough or rrate1= " %5.3f sensspec_h0 " at cutoff p=" `i' disp "Positive predictive value based on LR model plus r12cough or rrate1h= " %5.3f ppv_h " at cutoff p=" `i' disp "Negative predictive value based on LR model plus r12cough or rrate1= " %5.3f npv_h " at cutoff p=" `i' disp "Likelihood ratio based on LR model plus r12cough or rrate1= " %5.3f lr_h " at cutoff p=" `i' restore } Many thanks, Peter MacPherson Liverpool School of Tropical Medicine Dr Peter MacPherson MBChB MPH Wellcome Trust Clinical Research Fellow PhD Candidate Apt 5, 14 South Albert Road Liverpool, L17 8TN United Kingdom Mob: +447519592227 email: petermacpherson@mac.com skype:petermacpherso ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ * * 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/

- Prev by Date:
**st: AW: Running loop to test all possible combinations of variables** - Next by Date:
**Re: st: Panelvar** - Previous by thread:
**st: Panelvar** - Next by thread:
**st: Instrument variable** - Index(es):