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 at the end of May, and its replacement, statalist.org is already up and running.


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

RE: st: Dummy variable transformation replacing missing data


From   Nick Cox <n.j.cox@durham.ac.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Dummy variable transformation replacing missing data
Date   Mon, 11 Jun 2012 17:35:56 +0100

Yes, you can modify the command, but I don't think you are telling us enough about what you want. 

If there is just one non-missing value for each identifier, it seems that you want that value to apply to all observations for the same identifier. 

Some code then is 

egen xcount = count(x), by(id)
egen x1 = max(x) if xcount <= 1, by(id)

Note that if -x- always missing for an identifier, then -xcount- is 0 and -x1- is also missing. 

You need to define what should happen if there are two or more non-missing values for each identifier, especially if they conflict. 

Alternatively, read the FAQ that Ronnie pointed you to as it may be what you seek after all. 

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

Joe Dreyfus

I'm almost there. Nick is correct in anticipating that the result of -egen
xcount = count(x), by(id)- is more than one. The program suggested leads
to conflicts in the new variables where two different indicators are
switched on at different time periods.

Is it possible to modify the command so the when an indicator is switched
on (for example at t = 2), then it transformed to be switched on for all
time periods, sorted by individual? I think this will avoid conflict
described above.

On 11/06/12 5:10 PM, "Nick Cox" <n.j.cox@durham.ac.uk> wrote:

>That's a very good FAQ but it's not quite what Joe is asking for.
>
>Joe wants something like this:
>
>egen x1 = max(x), by(id)
>
>except to that to be safe this should only be used if the result of
>
>egen xcount = count(x), by(id)
>
>is at most one. 
>
>Nick 
>n.j.cox@durham.ac.uk
>
>Ronnie Babigumira
>
>This might be helpful
>
>http://www.stata.com/support/faqs/data/missing.html
>
>On Monday, June 11, 2012 at 2:54 PM, Joe Dreyfus wrote:
>
> 
>> I have the following data.
>> 
><snip>  
>> 
>> 
>> The time period where the indicator is on is not relevant. I just need
>>to know how to transform the variable so that if it is swtiched on in
>>one time period it is transformed to be switched on for all time
>>periods. 
>> 

*
*   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