I'm stuck on a very basic problem, I think. I need to set a dummy variable (year) to one from the year it has been one for the first time. Basically, each dummy should == its left neighbour if the left neighbour == 1.
Just have a look at the data and it will become obvious what I mean, I guess:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int(location_num partner_num) str6 agreement_num float(abkommen_dummy2007 abkommen_dummy2008 abkommen_dummy2009 abkommen_dummy2010 abkommen_dummy2011) 4 417 "371" . 1 . . . 4 586 "371" . 1 . . . 4 762 "371" . 1 . . . 4 792 "371" . 1 . . . 4 795 "371" . 1 . . . 4 860 "371" . 1 . . . 8 40 "8" . . 1 . . 8 56 "8" . . 1 . . 8 196 "8" . . 1 . . 8 203 "8" . . 1 . . 8 208 "8" . . 1 . . 8 233 "8" . . 1 . . 8 246 "8" . . 1 . . 8 251 "8" . . 1 . . 8 276 "8" . . 1 . . 8 300 "8" . . 1 . . 8 348 "8" . . 1 . . 8 352 "9" . . . 1 . 8 372 "8" . . 1 . . 8 381 "8" . . 1 . . end
For each observation, all the missing values to the right of the first 1 shall be 1 as well.
The dataset includes 6384 observations and the abkommen_dummy_years range from 1949 to 2019.
Afterwards, I will reshape the data to long format for a merge. (It was long format before with a variable "year".)
So if it is easier to create tons of new observations for each year after the starting year, this would be an alternative approach.
Here's an data example of the original long format:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int(location_num partner_num) str6 agreement_num int year float abkommen_dummy 4 417 "371" 2008 1 4 586 "371" 2008 1 4 762 "371" 2008 1 4 792 "371" 2008 1 4 795 "371" 2008 1 4 860 "371" 2008 1 8 807 "11" 2002 1 12 24 "461" 1989 1 12 32 "461" 1989 1 12 40 "17" 2005 1 12 48 "496" 1998 1 12 50 "461" 1989 1 12 56 "16" 1976 1 12 68 "461" 1989 1 12 72 "3" 1994 1 12 76 "461" 1989 1 12 120 "461" 1989 1 12 132 "3" 1994 1 12 140 "3" 1994 1 12 144 "461" 1989 1 end
Thank you so much!
Johannes
0 Response to Set Dummy Variable = 1 if the Dummy Variable left to it == 1
Post a Comment