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?
variable with multiple conditionsHello. I'm attempting to create a new variable (metabolic syndrome) based on meeting at least three…
Problems with simple adjusted logistic regression on small sample-size (n=13)Hi I am trying to make a simple logistic regression adjusted for one potential confounder ("Antibtio…
Extend window for variable labels in Stata's main windowHi, maybe I am not seeing sth. obvious, but how can I extend the space for variable labels in the ma…
Age-adjusted P values for differences between categorical or continuous variablesHi, I have a table of baseline characteristics of a cohort in which I have compared the differences…
Sample Size AUC/AUROCHi all, I'm working on a study that will evaluate several score to predict the same outcome (surviv…
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