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?
PCA vs MCA for index with survey weightsDear All, I am trying to calculate a wealth index using Principal Component Analysis. The quintiles…
Observations in descriptive and multivariate analysesHi, I am just writing to ask something about the observations in descriptive and multivariate analys…
Summarizing special character of string variable*Is there any command by which I can summarize special characters (e.g. *,-.) of string variable? …
2x2 AB/BA crossover trial analysis resources/adviceHi all. I would like to conduct the analysis of a trial comparing two drugs (A and B) on reducing p…
Constrained systems of sfcross regressions!Hi everyone, I'm trying to do something which I'm not sure is possible with Stata. Basically, I'm …
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