I am struggling with this problem which is very difficult to explain. I am trying my best to describe it here and really appreciate if anyone can help me.
My dataset based on a survey of the employment status of parents. It has 3 variables: id, year_of_survey, employment_status ( the variable "employment_status" is a dummy with two categories: 1= employed and 0= unemployed).
I want to create another dummy variable called: "unemployment_experience" to define which mother/father has been through unemployment at the time she/he was interviewed (a mother/father once was unemployed will be considered to have experience in unemployment from then on even if he is employed after that). It should take value 1 if from the time interviewing backward, employment_status=0 at least once) and 0 otherwise. (1 = have experience in unemployment , 0 = no experience in unemployment)
For example, I want to generate this following dataset:
id | year_of_survey | employment_status | unemployment_experience |
1 | 2000 | 1 | 0 |
1 | 2001 | 1 | 0 |
1 | 2002 | 0 | 1 |
1 | 2003 | 1 | 1 |
2 | 2000 | 1 | 0 |
2 | 2001 | 1 | 0 |
2 | 2002 | 1 | 0 |
2 | 2003 | 0 | 1 |
3 | 2000 | 0 | 1 |
3 | 2001 | 1 | 1 |
3 | 2002 | 1 | 1 |
3 | 2003 | 1 | 1 |
3 | 2004 | 1 | 1 |
3 | 2005 | 1 | 1 |
Best regards,
Cameron.
0 Response to create dummy variable based on condition of other variables
Post a Comment