Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

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

 From Tim Evans <[email protected]> To "'[email protected]'" <[email protected]> Subject st: RE: RE: RE: RE: flagging significant values in a variable Date Fri, 2 Mar 2012 11:41:49 +0000

```Graeme, Nick,

Thanks for your suggestions, much appreciated.

Best wishes

Tim

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: 02 March 2012 10:31
To: '[email protected]'
Subject: st: RE: RE: RE: flagging significant values in a variable

Or (with some loss of clarity)

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

Nick
[email protected]

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/

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