Hello everyone,
I was hoping someone could help me. I am trying to create a variable that would count each "1" until the following "0", as demonstrated in the example "newvar". This "newvar" is the variable I am trying to create, unsuccessfully... I am not sure if it is possible to reset the "sum" variable for each zero.
Expectation:
gov1change newvar
0
1 1
1 2
1 3
1 4
0
1 1
1 2
1 3
1 4
1 5
1 6
1 7
0
1 1
1 2
1 3
1 4
1 5
0
However, what I have is a variable called "gov1cum":
gen gov1cum = .
replace gov1cum = sum(inrange( gov1change[_n], 0,1)) if gov1change!=0
gov1change gov1cum
0
1 1
1 2
1 3
1 4
0
1 5
1 6
1 7
1 8
1 9
1 10
1 11
0
1 12
1 13
1 14
1 15
1 16
0
I would be very happy if someone could tell me if its possible to create such a variable... Thank you very, very much.
Cat
Related Posts with Help: Sequential Count in Between Two Variable Values
 Trying to run a predicted probabilities plot with a twoway scatterplot with a splineI accidentally created two threads of the same thing 
… Trying to run a predicted probabilities plot with a twoway scatterplot with a splineI accidentally created two threads of the same thing 
…
 GLS for non-linear equationln (Pit) = a*ln(Rit + b*Vit) + uit
I want to estimate a, b for wide panel data (i = 1~16, t = 2007~… GLS for non-linear equationln (Pit) = a*ln(Rit + b*Vit) + uit
I want to estimate a, b for wide panel data (i = 1~16, t = 2007~…
 Missing variables using reshape wide commandHi,
This is the command I'm using-
reshape wide day_piece, i(farm) j(day_sales) string
And this is… Missing variables using reshape wide commandHi,
This is the command I'm using-
reshape wide day_piece, i(farm) j(day_sales) string
And this is…
 Tried several variations...need help with graphing a predicted probabilities plot with twoway scatter plot and splinedHi Statalist,
I cannot figure out how to do this... the attached graph is exactly what we want, but … Tried several variations...need help with graphing a predicted probabilities plot with twoway scatter plot and splinedHi Statalist,
I cannot figure out how to do this... the attached graph is exactly what we want, but …
 match age and genderHello, I would like to know how to match 2:1 for age and gender using same sample of individuals. I … match age and genderHello, I would like to know how to match 2:1 for age and gender using same sample of individuals. I …
Subscribe to:
Post Comments (Atom)
0 Response to Help: Sequential Count in Between Two Variable Values
Post a Comment