Hello there,
I'm currently working with a paneldata set where observations are identified by a personal id (variable name: pid) and the year (variable name: syear). While this paneldata set includes a variable called KINDHIP, describing the kind of health insurance of individual i in year t, I need for replication reasons yearly variables like KINDHIP2007 describing the kind of health insurance person i had in year 2007. The value of this variable should be the same in all years for the single pids so that I can select all yearly observations for persons that had a certain value for KINDHIP in 2007. To make it more clear: I can't just use an if-clause since I don't just want e.g. all 2007-oberservations with KINDHIP == 2, but ALL observations over the whole time horizon for persons that have KINDHIP == 2 in 2007.
I tried
gen kindhip2007 = .
by pid (syear), sort: replace kindhip2007 = KINDHIP[syear == 2007]
and understood why this isn't working, but unfortunately can't find a solution.
Edit: For some individuals there are certain years missing in the paneldata set and I need to treat these wholly missing years (there doesn't even exist a pid-syear-combination for these in the dataset) like missing-values.
Thanks a lot!
I'm currently working with a paneldata set where observations are identified by a personal id (variable name: pid) and the year (variable name: syear). While this paneldata set includes a variable called KINDHIP, describing the kind of health insurance of individual i in year t, I need for replication reasons yearly variables like KINDHIP2007 describing the kind of health insurance person i had in year 2007. The value of this variable should be the same in all years for the single pids so that I can select all yearly observations for persons that had a certain value for KINDHIP in 2007. To make it more clear: I can't just use an if-clause since I don't just want e.g. all 2007-oberservations with KINDHIP == 2, but ALL observations over the whole time horizon for persons that have KINDHIP == 2 in 2007.
I tried
gen kindhip2007 = .
by pid (syear), sort: replace kindhip2007 = KINDHIP[syear == 2007]
and understood why this isn't working, but unfortunately can't find a solution.
Edit: For some individuals there are certain years missing in the paneldata set and I need to treat these wholly missing years (there doesn't even exist a pid-syear-combination for these in the dataset) like missing-values.
Thanks a lot!

Comment