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
Joe Canner <[email protected]>
To
"[email protected]" <[email protected]>
Subject
RE: st: Binary variable (create a flag) in STATA and deleting variables
Date
Sun, 12 Jan 2014 23:02:09 +0000
John,
The answer to your second question is no, if you use the value of one variable to create another variable, dropping or changing the original variable will not change the derived variable. Commands in Stata are run on all observations in the dataset (subject of course to any if/in conditions used in the command) before moving on the next command.
Regards,
Joe
________________________________________
From: [email protected] [[email protected]] on behalf of Alfonso Sánchez-Peñalver [[email protected]]
Sent: Sunday, January 12, 2014 5:36 PM
To: Stata List
Subject: Re: st: Binary variable (create a flag) in STATA and deleting variables
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/
*
* 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/