I want to create a new variable "signal" in this long format data set. The rule is set below,
if all status values equal 1 within id, then signal==NR
if all status values equal 0 within id, then signal==1
if the first 0 occurs several consecutive 1 within id, then signal==number of the consecutive status value (which is one)+1
For example, for id==1, signal=3+1=4
*Simulated data for illustrative purpose.
clear
input byte (id status)
1 1
1 1
1 1
1 0
1 0
1 0
1 0
1 0
1 0
2 0
2 0
2 0
2 0
2 0
3 1
3 1
3 1
3 1
3 1
3 1
3 1
4 1
4 0
4 0
4 0
end
Thank you for your help!
Related Posts with How can I recode the variable in this long format data set with Stata?
Controlling for differences caused by occupationHello - I am new to the world of econometrics and am working on a small research paper. I am trying …
Negative statistic chi2 after hausman testHello everyone, I have panel data and my dependent variable is a dummy variable. N=801 (individuals)…
Stata vs Mplus for LPA?Dear researchers, I am trying to conduct Latent Profile Analysis but wonder conducting it with Stat…
How should I fix this error in my scatter plot?Hello, I've been trying to make a more advanced scatter plot and have managed to figure out the bit…
Using the character ehat_t in the y-axisDear all, I hope you are all keeping well! I want to use the character ehat_t in my y-axis So I t…
Subscribe to:
Post Comments (Atom)
0 Response to How can I recode the variable in this long format data set with Stata?
Post a Comment