Hi Statlist colleagues,
hope you are doing very well.
I am facing a problem writing up codes for the following:
So I have first dataset which looks like following:
Here I'd like to merge a variable but with some manipulation. There is this variable named 'resid' from another dataset, and I want to merge the 4-week sum of that variable to each observation in the first dataset.
For example, for the first observation in the first dataset, the date is 06jan2005, so I want to match the sum of all observations for the previous 4-week from 06jan2005.
To show in dataset,
for example, the second dataset looks like this:
Then for the first observation in the first dataset, date was 06jan2005 , so I want to match it with the sum of 'resid' in second dataset for 20dec2004 and 03jan2005 because those two are the only two that are within the previous 4-week period.
For the second last observation in the first dataset, date was 04feb2005, so I want to match it with the sum of 'resid' in second dataset for 07jan2005 08jan2005 11jan2005 14jan2005 18jan2005 23jan2005 28jan2005 as they are all within previous 4-week period from 04feb2005.
I could not figure out how to implement this merging in stata, and wanted to ask if you have any ideas rather than matching them in excel.
Thanks much,
Jinny
hope you are doing very well.
I am facing a problem writing up codes for the following:
So I have first dataset which looks like following:
Code:
date payroll jobclaim umemp 06jan2005 0 6.13 0 07jan2005 -.52 0 0 13jan2005 0 2.78 0 19jan2005 0 -3.63 0 27jan2005 0 -1.11 0 03feb2005 0 -1.78 0 04feb2005 -1.94 0 -4.91
For example, for the first observation in the first dataset, the date is 06jan2005, so I want to match the sum of all observations for the previous 4-week from 06jan2005.
To show in dataset,
for example, the second dataset looks like this:
Code:
date resid 20dec2004 0.22 03jan2005 -0.32 07jan2005 0.29 08jan2005 0 11jan2005 0.23 14jan2005 0.43 18jan2005 0 23jan2005 0.23 28jan2005 0.43
For the second last observation in the first dataset, date was 04feb2005, so I want to match it with the sum of 'resid' in second dataset for 07jan2005 08jan2005 11jan2005 14jan2005 18jan2005 23jan2005 28jan2005 as they are all within previous 4-week period from 04feb2005.
I could not figure out how to implement this merging in stata, and wanted to ask if you have any ideas rather than matching them in excel.
Thanks much,
Jinny
Comment