Hi there,
I am certain this is a stupid question (but I can't figure it out!). I have 2 variables in my dataset: date, recorded monthly, and value.I want to make a new variable (call it var) that =1 if the sum of the values over the past 36 months are positive (and zero otherwise).
I am struggling with the 36 months part. I cannot figure out how to sum up the values without having something like:
Is there a simpler way to do this?
Thanks for any help.
I am certain this is a stupid question (but I can't figure it out!). I have 2 variables in my dataset: date, recorded monthly, and value.I want to make a new variable (call it var) that =1 if the sum of the values over the past 36 months are positive (and zero otherwise).
I am struggling with the 36 months part. I cannot figure out how to sum up the values without having something like:
Code:
gen yy = year(date) gen mm = month(date) sort yy mm gen var = value[_n-1] +value[_n-2] + ... + value[_n-36] replace var = 1 if var>0 replace var =0 if var!=1
Thanks for any help.
Comment