Hi everyone!
I want to create a dummy variable (Dum2) that is 1 based on the condition that another dummy (Dum1) is 1 in a certain condition (year; Cond1) for all observations of ID.
This table should be helpful to illustrate my problem and to show how I want Dum2 to behave:
To generate Dum1 I did
Dum2 should be 1 for all ID, if Dum1 is 1 under Cond1==2002 (in year 2002)
Put differently, Dum2 should be 1 for all Cond1, if Cond2 is met under Cond1==2002.
I tried to generate Dum2 by
or constructions like
but this causes Dum2==1 only when Cond1==2002 and thus not for all Cond1 of ID, which is what I want.
I am a novice to Stata and statistical software in general so I hope this is not too dull to be posted here, but I did search through all the documentation and manuals I could find and wasn't able to come up with anything that worked.
For your help thank you very much in advance!
Best regards,
Roman
I want to create a dummy variable (Dum2) that is 1 based on the condition that another dummy (Dum1) is 1 in a certain condition (year; Cond1) for all observations of ID.
This table should be helpful to illustrate my problem and to show how I want Dum2 to behave:
ID | Cond1 (year) | Cond2 (value; 0-1) | Dum1 (Cond2>.5) | Dum2 |
A | 2001 | .5 | 0 | 0 |
A | 2002 | .8 | 1 | 0 |
A | 2003 | .2 | 0 | 0 |
B | 2001 | .3 | 0 | 1 |
B | 2002 | .3 | 0 | 1 |
B | 2003 | .6 | 1 | 1 |
C | 2001 | .6 | 1 | 0 |
C | 2002 | .7 | 1 | 0 |
C | 2003 | .6 | 1 | 0 |
To generate Dum1 I did
Code:
generate Dum1 = Cond2>.5 if !missing(Cond2)
Put differently, Dum2 should be 1 for all Cond1, if Cond2 is met under Cond1==2002.
I tried to generate Dum2 by
Code:
generate Dum2 = Cond2<=.5 if Cond1==2002 & !missing(Cond2)
Code:
levelsof ID, local(levels) foreach ID of local levels { generate Dum2=1 if Dum1==1 & Cond1==2002 }
I am a novice to Stata and statistical software in general so I hope this is not too dull to be posted here, but I did search through all the documentation and manuals I could find and wasn't able to come up with anything that worked.
For your help thank you very much in advance!
Best regards,
Roman
Comment