11-26-2015 11:51 AM
I currently have a dataset with 1 observation per firm in various years. For example, I have a firm with a 1998 observation. Is there a way to code it where I can get lines for 1995, 1996, 1997, 1999, 2000, and 2001 observations for the same firm (3 years before and 3 years after)? That way, instead of having 1 observation per firm, I will have 7. Finally, I would like to delete the original observation (1998 in my example).
Thanks so much!
11-26-2015 02:15 PM
This code is working , but i think you get better soluation in this forum .
data newdata; Input Id$ Year; datalines; A 1998 ; run; Data want1; set newdata; Do i = 1 to 3; Year1 = Year+(i); Output; End; drop i year; run; Data want2; set newdata; Do i = 1 to 3; Year2 = Year-(i); Output; End; drop i year; run; Proc SQL; Select* from want1 union All Select* from want2; quit;
11-26-2015 02:37 PM - edited 11-26-2015 02:38 PM
An simpler coding variant for what you're proposing is:
data have; input Id$ Year; datalines; A 1998 ; run; data want(drop=_y); set have(rename=(year=_y)); do year= _y-3 to _y-1 , _y+1 to _y+3 ; output; end; run;
11-26-2015 04:08 PM - edited 11-26-2015 04:09 PM
The do loop allows for quite a few different variations of syntax.
Have a look at Example1:
11-26-2015 03:02 PM - edited 11-26-2015 03:09 PM
What should happen if a firm has multiple entries in your source dataset?
Can you please show us your desired result for _cik=0001046649
Not my area of expertise but should you intend to create such data as preparation for time series then look into Proc Expand.
11-27-2015 06:26 AM
Thanks for the help - God bless you and your family! The reason there are multiple entries of the same firm is because I have a treatment group and a control group; with the control group, I did matching with replacement. It would be great to know how to do matching without replacement for the future.