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?
Marginal Effects on ivprobitI'm running an ivprobit model, and I'm trying to get marginal effects out of the second stage coeffi…
Calculating BMI when ht and wt have been recorded with different unitsHello, I am trying to create a new variable for BMI and I have a dataset with continuous variable "…
Mauchly's test of sphericity commandI am trying to test the assumption of sphericity for the purpose of running a repeated measures ANOV…
Count model with data panel ( poisson)Hi, I'm new here (and new to stata/statistical analysis) i need help with a count model with data pa…
Re-arrange variablesDear all, I have 30 variables in different columns. Now I want Stata to generate one new variable w…
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