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: combine 2 variables
From
Jorge Eduardo Pérez Pérez <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: combine 2 variables
Date
Wed, 12 Feb 2014 00:29:54 -0500
I feel that what you want is to generate a single diagnostic variable
that has a different value for any combination of diag1 and diag2, and
label it appropiately. This is just my interpretation of your rather
not well explained problem.
If this is what you want, here's an example. -labmask- is from SSC, so
you need to install it first.
clear
input diag1 diag2
1 .
2 .
3 .
1 2
end
label define diag_lbl 1 "Hem" 2 "Asph" 3 "Strk"
la val diag1 diag_lbl
la val diag2 diag_lbl
list
* Generate the new variable
egen cdiag=group(diag1 diag2), missing
list
* Label it with a combination of the other labels
* Decode the labels
decode diag1, gen(labdiag1)
decode diag2, gen(labdiag2)
* Combine them
gen plus="+" if diag2!=.
gen labcdiag=labdiag1+plus+labdiag2
drop plus
* Now assign labcdiag as value label for cdiag
labmask cdiag, val(labcdiag) lblname(cdiag_lbl)
drop lab*
li
des
--------------------------------------------
Jorge Eduardo Pérez Pérez
Graduate Student
Department of Economics
Brown University
On Tue, Feb 11, 2014 at 3:54 PM, Nick Cox <[email protected]> wrote:
> You have not answered all my questions, so at this point I give up.
> Someone else may want to guess what you want.
> Nick
> [email protected]
>
>
> On 11 February 2014 20:51, Dao Kim <[email protected]> wrote:
>> Id 101 to 175 identifies the patients
>>
>> -----Message d'origine-----
>> De : [email protected] [mailto:[email protected]] De la part de Dao Kim
>> Envoyé : mardi 11 février 2014 21:51
>> À : '[email protected]'
>> Objet : RE: st: combine 2 variables
>>
>> Hi Nick, dg1 and dg2 are string variables, all the same (hemorrhage, stroke, asphyxia, malformative, infectious, others), I converted them into numeric variables. Each ID has at least 1 diagnosis (dg1), only 5 have a 2nd diagnosis (dg2). In order to analyse diagnoses as a whole. Thanks Here is the description
>>
>> . describe cat_dg1 cat_dg2
>>
>>
>>
>> storage display value
>>
>> variable name type format label variable label
>>
>> ------------------------------------------------------------------------------------------------------------------------------------------
>>
>> cat_dg1 long %12.0g cat_dg1
>>
>> cat_dg2 long %12.0g cat_dg2
>>
>>
>>
>> . list cat_dg1 cat_dg2 in 1/10
>>
>>
>>
>> +----------------------+
>>
>> | cat_dg1 cat_dg2 |
>>
>> |----------------------|
>>
>> 1. | hemorrhage . |
>>
>> 2. | asphyxic . |
>>
>> 3. | hemorrhage . |
>>
>> 4. | stroke . |
>>
>> 5. | others . |
>>
>> |----------------------|
>>
>> 6. | hemorrhage . |
>>
>> 7. | asphyxic . |
>>
>> 8. | others . |
>>
>> 9. | hemorrhage . |
>>
>> 10. | asphyxic . |
>>
>> +----------------------+
>>
>>
>>
>> -----Message d'origine-----
>> De : [email protected] [mailto:[email protected]] De la part de Nick Cox Envoyé : mardi 11 février 2014 20:28 À : [email protected] Objet : Re: st: combine 2 variables
>>
>> Thanks, but we (I) still don't know what your variable types and values are, exactly.
>>
>> Please show the results of
>>
>> . describe dg1 dg2
>>
>> . list dg1 dg2 in 1/10
>>
>> Also add to the variables above whatever identifies your patients.
>> (Use anonymous equivalents by all means if confidentiality is an
>> issue.)
>>
>> Also, show what a new variable should look like.
>>
>> Nick
>> [email protected]
>>
>>
>> On 11 February 2014 19:22, Dao Kim <[email protected]> wrote:
>>> Most of my patients have 1 diagnosis: ie hemorrhage, asphyxia or
>>> stroke (variable dg1) Some have 2: hemorrhage and asphyxia (another variable dg2); is it possible to associate these two as only one variable for one patient? I am trying to evaluate the efficacy of a drug according to the diagnosis, there are so few patients with 2 diagnoses (dg2) that it doesn't make sense to use it isolated. it does this make more sense?
>>>
>>> -----Message d'origine-----
>>> De : [email protected]
>>> [mailto:[email protected]] De la part de Nick Cox
>>> Envoyé : mardi 11 février 2014 20:07 À :
>>> [email protected] Objet : Re: st: combine 2 variables
>>>
>>> Dao Kim:
>>>
>>> This is incomprehensible.
>>>
>>> "combine": what does that mean?
>>>
>>> "Concat" doesn't work. I guess that you tried -egen, concat()- but what exactly did you try? What do you mean by "doesn't work"? What did it do? Why isn't that what you want?
>>>
>>> "merge 1:1 id" -merge- is for merging two or more datasets. That is a completely different problem from combining two variables.
>>>
>>> But forget all that.
>>>
>>> What are your variables?
>>>
>>> What are your observations?
>>>
>>> Please show us an example of your data.
>>>
>>> Please show us an example of what you want to get.
>>>
>>>
>>> Nick
>>> [email protected]
>>>
>>>
>>> On 11 February 2014 18:59, Dao Kim <[email protected]> wrote:
>>>> Dear Statalists, I try to combine two diagnoses variables to one, for patients that mostly only have 1 diagnosis for seizures etiology, but a minority has 2 etiologies/diagnoses, I can't figure out how to make only one variable. Concat doesn't work, I tried to merge 1:1 id , any idea? Thanks for your help!
>>>>
>>>> *
>>>> * 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/
>>
>> *
>> * 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/
>
> *
> * 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/