```Date: Fri, 13 Jul 2001 12:41:25 -0500 Reply-To: "Gregg P. Snell" Sender: "SAS(r) Discussion" From: "Gregg P. Snell" Organization: Data Savant Consulting Subject: Re: Questions on a very simple "Data manipulation" Content-Type: text/plain; charset="iso-8859-1" Hi Shane, Here is one solution: data test; input firm \$ X1 X2; cards; firm1 10 5 firm1 15 23 firm1 16 23 firm1 20 13 firm2 5 20 firm2 6 16 firm2 2 11 firm2 20 13 ; run; proc sort data=test; by firm; run; data new; set test; by firm; retain x3; if first.firm then do; x3=1; x4=.; end; else do; x3=x3+1; x4=mean(x1,lag(x1)); end; run; HTH... Gregg P. Snell Data Savant Consulting (913) 638-4640 (208) 977-1943 fax http://www.datasavantconsulting.com Co-chair of MWSUG 2001 http://www.mwsug.org/mw_2001/index.htm Shane Jun wrote in message news:1b60e24d.0107130915.17ae6ce0@posting.google.com... > Hi Everyone, > > A SAS beginner is struggling with a seemingly simple problem. > > I am dealing with a panel dataset: multiple firms with multiple > periods. > > My dataset looks like this, > > firm X1 X2 > > firm1 10 5 > firm1 15 23 > firm1 16 23 > firm1 20 13 > > firm2 5 20 > firm2 6 16 > firm2 2 11 > firm2 20 13 > > Of course, the original dataset includes much greater number of > obervations for each firm. > > I need to add two new variables in the dataset. > > The first one is time period. The variable will be an index variable > starting from 1 to the last observation of each firm. (The dataset is > arranged by the period already) > > I need the new variable in order to run the regression for each > period. > > SO the new variable X3 will look like > > firm X1 X2 X3 > > firm1 10 5 1 > firm1 15 23 2 > firm1 16 23 3 > firm1 20 13 4 > > firm2 5 20 1 > firm2 6 16 2 > firm2 2 11 3 > firm2 20 13 4 > > The second variable that I need to add is the mean of X1 of two > previous observations for each firm. > > This variable will start in the second obervation for each firm. > Calling it X4, the new dataset would look like, > > firm X1 X2 X3 X4 > > firm1 10 5 1 . > firm1 15 23 2 mean of 10 and 15 > firm1 16 23 3 mean of 15 and 16 > firm1 20 13 4 mean of 16 and 20 > > firm2 5 20 1 . > firm2 6 16 2 mean of 5 and 6 > firm2 2 11 3 mean of 6 and 2 > firm2 20 13 4 mean of 2 and 20 > > WOuld anyone help me with this? > > Thanks in advance. > > Shane > ```

Back to: Top of message | Previous page | Main SAS-L page