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: Binary variable (create a flag) in STATA and deleting variables


From   Matt Vivier <[email protected]>
To   [email protected]
Subject   Re: st: Binary variable (create a flag) in STATA and deleting variables
Date   Sun, 12 Jan 2014 18:01:12 -0500

Hello all,

Your code is a bit confusing, and looks like it may not produce the
result you want if you continue the pattern to include:
replace cancer = 0 if medicalcode !="25C5.00"

I'm a fan if using -inlist-:

gen cancer = 0
replace cancer = 1 if inlist(medicalcode,"88Zuu00","25C5.00","25C5.01")

If you have ~200 codes you will encounter a pretty unpleasant
situation with the limits though. From my limited understanding of
your data structure, my approach would be a bit different. I would
create a separate file of "Cancer Codes" called cancercodes.dta and
merge that in, using the _merge variable to help you discover your
cancer patients.

sort medicalcode
merge m:1 medicalcode using cancercodes.dta
gen cancer = cond(_merge==3,1,0)

Keep in mind this is only good for flagging patients if each patient
has just one record in your file. Otherwise you may get some
conflicting results.

Best,
Matt Vivier
Data Analyst
Remedy Partners, Inc


On Sun, Jan 12, 2014 at 5:36 PM, Alfonso Sánchez-Peñalver
<[email protected]> wrote:
> Hi,
>
> to generate the binary variable you just need to write one command, but it will have to have all codes. Thus
>
> gen cancer = (medicalcode == "88zuu00" | medicalcode == "25C5.00" | etc.)
>
> where etc will be a series of medicalcode == to the different codes that reflect cancer. I am not sure I understand the second question you ask.
>
> Best,
>
> Alfonso Sanchez-Penalver
>
> On Jan 12, 2014, at 5:30 PM, [email protected] wrote:
>
>> Dear all,
>>
>> I have two questions:
>>
>> 1. I want to create a binary variable (create a flag) in STATA
>>
>> I’ve got a file cancer.dta
>> - containing list of medical codes (e.g. 88Zuu00, 25C5.00) that mean a
>> person has a cancer.
>>
>> I have also a second file health_record.dta
>> - with different variables about patient. One of the variables are
>> medical codes (for cardiovascular disease, diabetes and of course
>> CANCER).
>>
>> I want to create a binary variable (flag) that would indicate if a
>> person has cancer.
>>
>> So far I did something like this:
>>
>> gen cancer=.
>> replace cancer = 1 if medicalcode=="88Zuu00"
>> replace cancer = 0 if medicalcode !=" 88Zuu00"
>> replace cancer = 1 if medicalcode =="25C5.00" | medicalcode == "25C5.01" | etc.
>>
>> But etc. in this case means that I have to reaped the command for over
>> 200 cases. Is there a quicker, more sufficient way?
>>
>> 2. Will deleting a variable that I created just to count other
>> variables affect their result? Like in Excel when I delete a cell,
>> then if there was reference to that cell it is all gone. Is Stata the
>> same in that matter?
>>
>> I apologize if you so the first question already in another message. I
>> think that for future reference this problem should be in separate
>> message.
>>
>> Kind Regards
>>
>> John
>>
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/

-- 
The information contained in this transmission and any attachments may be 
confidential, proprietary  or privileged, and may be subject to protection 
under applicable law. This transmission is intended for the sole use of the 
individual or  entity to whom it is addressed. If you think you have 
received this transmission in error, please alert 
[email protected] and then delete this e-mail immediately. 
Thank you.

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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