Hi
I have a two panel data set with a ordered response variable in it, call it "Pain". Pain takes values 1-5, with 1 being a lighter level of pain. I'd like a to generate a variable that is -1 for a positive change in in Pain, 0 for no change and 1 for negative change. Below is what I did that eventually worked. I'd like to know a better way as one must exist.
gen chng = pain- L.pain if !missing(pain)
generate hidy = 1 if chng < 0 & !missing(chng)
replace hidy = -1 if chng >0 & !missing(chng)
replace hidy = 0 if chng == 0 & !missing(chng)
I leaving out all the tabulations i did to make sure it was right.
There has to be a better way to do this. I know its whiny but I'd like to learn the language better.
I have a two panel data set with a ordered response variable in it, call it "Pain". Pain takes values 1-5, with 1 being a lighter level of pain. I'd like a to generate a variable that is -1 for a positive change in in Pain, 0 for no change and 1 for negative change. Below is what I did that eventually worked. I'd like to know a better way as one must exist.
gen chng = pain- L.pain if !missing(pain)
generate hidy = 1 if chng < 0 & !missing(chng)
replace hidy = -1 if chng >0 & !missing(chng)
replace hidy = 0 if chng == 0 & !missing(chng)
I leaving out all the tabulations i did to make sure it was right.
There has to be a better way to do this. I know its whiny but I'd like to learn the language better.
Comment