Dear everyone,
For example, I have panel data set like this:
I want to create a dummy variable named "quit" for year t based on the variable "same_employer" in the year (t+1). If the variable "same_employer" takes "No" in the year (t+1), then the "quit" variable at year t takes a value of 1.
For example, for person ID 1, we see that in 2001 his answer is "Yes" for "same_employer", then his "quit" variable in 2000 would be 0.
Here is the code that I have used:
However, since I am using the information in the year (t+1) to create a dummy for year t; therefore, the final year of each person_id would have a missing value. For example, for person_id 1, the "quit" variable for the year 2002 would have a missing value.
My question here is, how do I generate a missing value in this case since each person_id has a different final year? The code above does not generate a missing value. Here is an example of what I am looking for:
Thank you for your help. Please also let me know if my code is correct.
For example, I have panel data set like this:
Code:
clear input double person_id int year str3 same_employer 1 2000 "Yes" 1 2001 "Yes" 1 2002 "No" 2 2000 "No" 2 2001 "Yes" 2 2002 "No" 3 2000 "No" 3 2001 "No" 4 2000 "Yes" end
For example, for person ID 1, we see that in 2001 his answer is "Yes" for "same_employer", then his "quit" variable in 2000 would be 0.
Here is the code that I have used:
Code:
gen quit=0 bysort person_id (year): replace quit=1 if same_employer[_n+1]=="No"
My question here is, how do I generate a missing value in this case since each person_id has a different final year? The code above does not generate a missing value. Here is an example of what I am looking for:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double person_id int year str3 same_employer double quite 1 2000 "Yes" 0 1 2001 "Yes" 1 1 2002 "No" . 2 2000 "No" 0 2 2001 "Yes" 1 2 2002 "No" . 3 2000 "No" 1 3 2001 "No" . 4 2000 "Yes". end

Comment