Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: RE: RE: flagging significant values in a variable


From   Nick Cox <n.j.cox@durham.ac.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: RE: flagging significant values in a variable
Date   Fri, 2 Mar 2012 10:30:39 +0000

Or (with some loss of clarity) 

gen lag = cond(LCI > UCI[_N], 1, (UCI < LCI[_N]) * 2) if region != 99 

Nick 
n.j.cox@durham.ac.uk 

MacLennan, Graeme

Tim, this will do the same thing if region 99 is always the last observation in the file

gen flag = 0
replace flag = 1 if LCI > UCI[_N]
replace flag = 2 if UCI < LCI[_N]
replace flag = . if region == 99

Tim Evans

I did come up with a solution, but its probably not that clean, but it worked:

gen LCI3 = LCI if region==99
gen UCI3 = UCI if region==99
replace  LCI3 = LCI3[_n-1] if missing(LCI3) replace  UCI3 = UCI3[_n-1] if missing(UCI3) gen long flag=.
replace flag = 1 if  LCI> UCI3 & region!=99 replace flag = 2 if UCI<LCI3 & region!=99 replace flag = 0 if flag==. & region !=99 label define sig_test 0 "Not sig" 1 "Sig higher" 2 "Sig lower"
label values flag sig_test
drop UCI3 LCI3
sort region
list end - flag

     +---------------------------------------------------+
     | end    rate      LCI      UCI   region      flag |
     |---------------------------------------------------|
  1. |   5   0.9727   0.9583   0.9849        1   Not sig |
  2. |   5   0.9713   0.9523   0.9867        2   Not sig |
  3. |   5   0.9835   0.9667   0.9971        3   Not sig |
 13. |   5   0.9790   0.9741   0.9836       99         . |
     +---------------------------------------------------+

Is there a better way?

Tim Evans

I have a dataset that has variables of rates, LCI and UCI for a number of regions in addition to a national average (rate, LCI, UCI) so that it looks like this:

rate            LCI             UCI             region
0.9727  0.9583  0.9849  1
0.9713  0.9523  0.9867  2
0.9835  0.9667  0.9971  3
0.9790  0.9741  0.9836  99

What I would like to do is generate a flag beside each row that will flag up entries where they are significantly higher (1) or lower (2) or not significantly different (0) to region 99 - I'm unsure as to the code here and would appreciate any advice. I'm using Stata 11.2.


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index