Hi everyone,
I'm having a trouble creating a variable to measure changes in distance overtime using a panel data. For example: I create a var, name base12. This var contains information about distance of a household to the main road. In this case, we only pay attention to households whose distance is from 0~1km in 2012. Now I want to create another var, base14 for example. This var, base14 contains households whose characteristics are: having a distance of 0~1km in 2012 but somehow having a distance significantly larger than 1km (maybe 2 or 3km because the household moved away) in 2014.
I have tried as follow, yet it's not no effective and cannot satisfy my needs for a variable.
bysort ID: gen base12=dist_b if (inrange(dist_b,0,1)) & YR==2012
drop if base12==.
bysort base12: gen base14=dist_b if dist_b>1
replace base14=0 if base14==.
I have made an example of my data as follow:
input float ID int YR float dist_b
I appreciate any of your help.
All the best.
I'm having a trouble creating a variable to measure changes in distance overtime using a panel data. For example: I create a var, name base12. This var contains information about distance of a household to the main road. In this case, we only pay attention to households whose distance is from 0~1km in 2012. Now I want to create another var, base14 for example. This var, base14 contains households whose characteristics are: having a distance of 0~1km in 2012 but somehow having a distance significantly larger than 1km (maybe 2 or 3km because the household moved away) in 2014.
I have tried as follow, yet it's not no effective and cannot satisfy my needs for a variable.
bysort ID: gen base12=dist_b if (inrange(dist_b,0,1)) & YR==2012
drop if base12==.
bysort base12: gen base14=dist_b if dist_b>1
replace base14=0 if base14==.
I have made an example of my data as follow:
input float ID int YR float dist_b
1 | 2012 | 0 | |
2 | 2014 | 2 | |
3 | 2012 | 1 | |
4 | 2014 | 9 | |
5 | 2012 | 9 | |
1 | 2014 | 2 | |
2 | 2012 | 8 | |
3 | 2014 | 10 | |
4 | 2012 | 1 | |
5 | 2014 | 4 | |
1 | 2012 | 1 | |
2 | 2014 | 4 | |
3 | 2012 | 7 | |
4 | 2014 | 8 | |
5 | 2012 | 6 | |
1 | 2014 | 6 | |
2 | 2012 | 7 | |
3 | 2014 | 10 | |
4 | 2012 | 1 | |
5 | 2014 | 3 | |
1 | 2012 | 1 | |
2 | 2014 | 9 | |
3 | 2012 | 4 | |
4 | 2014 | 1 | |
5 | 2012 | 8 |
All the best.
Comment