Have trouble with replicating the RESTATEMENT example
Posted: 28 January 2015 01:33 AM   [ Ignore ]
Newbie
Rank
Total Posts:  8
Joined  2015-01-26

Hi, I am trying to run the RESTATEMENT SAS code

http://www.wrds.us/index.php/tutorial/view/restatement_event_study

However, I met a problem when I was doing the CAR’s part:

Original code:
/* compute CAR’s */
data myLib2.n_CAR (keep = key r_3day car_vw counter alpha beta );
set myLib2.m_withdailyIndex;
/* by key means that it will run through these statements for each key,
where key is a unique identifier of one observation
*/
by key;
/* retain means that the contents of these variables will be available
for example, counter will be set to zero with every observation
with every row of data (return), it will increase by 1
“if last.key then output” will write the value of the counter to the newly
created dataset
 
r_3day: 1 + 3 days of returns
car_vw: 3-day cumulative abnormal return
*/
retain counter r_3day car_vw;
if first.key then counter=0;
if first.key then car_vw=1;
if first.key then r_3day=1;
 
if ret eq . then ret = 0;
counter+1;
 
/* cumulative abnormal return */
car_vw = car_vw + ret - (alpha+beta * vwretd);
 
/* raw return, 3 day cumulative */
r_3day = r_3day + ret;
 
/* we are only interested in keeping the cumulative 3 day return (and not
cumulative 1 and 2 day) */
if last.key then output;
run;


my log result:

ERROR: BY variables are not properly sorted on data set WORK.M_WITHDAILYINDEX.
DATE=19970415 vwretd=0.011996 PERMNO=10187 RET=0.000000 press_date=04/16/1997 key=13620_HPLX
alpha=0.0062112012 beta=1.0203537358 FIRST.key=1 LAST.key=1 counter=1 r_3day=1.0730593577
car_vw=1.0629233614 _ERROR_=1 _N_=15
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 16 observations read from the data set WORK.M_WITHDAILYINDEX.
WARNING: The data set WORK.N_CAR may be incomplete.  When this step was stopped there were 6
      observations and 6 variables.
NOTE: DATA statement used (Total process time):
    real time       0.03 seconds
    cpu time         0.03 seconds

 


Can anyone help me to find my mistake?

Thanks.

 

Profile
 
 
Posted: 28 January 2015 08:35 AM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  901
Joined  2011-09-19

hi,

A data step that uses the ‘by’ statement needs the input data to be sorted by the same variable that it is grouping by. In this case, run this code first:

proc sort data=myLib2.m_withdailyIndexby key;run

best regards,

Joost

 Signature 

To reply/post new questions: Please use the group WRDS/SAS on Google Groups! http://groups.google.com/d/forum/wrdssas

Profile
 
 
Posted: 28 January 2015 09:58 AM   [ Ignore ]   [ # 2 ]
Newbie
Rank
Total Posts:  8
Joined  2015-01-26
Joost Impink - 28 January 2015 08:35 AM

hi,

A data step that uses the ‘by’ statement needs the input data to be sorted by the same variable that it is grouping by. In this case, run this code first:

proc sort data=myLib2.m_withdailyIndexby key;run

best regards,

Joost

 

Hi, Thank you so much, Joost. That problem is solved!
But when I ran the revised code, it shows a new problem:

NOTE: Variable first.key is uninitialized.
NOTE: Variable last.key is uninitialized.
NOTE: Missing values were generated as a result of performing an operation on missing values.
    Each place is given by: (Number of times) at (Line):(Column).
    1658 at 577:17   1658 at 580:17
NOTE: There were 1658 observations read from the data set WORK.M_WITHDAILYINDEX.
NOTE: The data set WORK.N_CAR has 0 observations and 6 variables.
NOTE: DATA statement used (Total process time):
    real time       0.04 seconds
    cpu time         0.01 seconds

 


I am almost done with the replication practice and I really need to solve the problem of how to do ‘CARs’.
Can you help me with the new problem? How to deal with “NOTE: Variable first.key is uninitialized.
NOTE: Variable last.key is uninitialized.

Thanks.

Profile
 
 
Posted: 28 January 2015 10:07 AM   [ Ignore ]   [ # 3 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  901
Joined  2011-09-19

hi,

Can you visually inspect the dataset and make sure the dataset is not empty and that ‘key’ exists?

best regards,

Joost

 Signature 

To reply/post new questions: Please use the group WRDS/SAS on Google Groups! http://groups.google.com/d/forum/wrdssas

Profile
 
 
Posted: 28 January 2015 03:50 PM   [ Ignore ]   [ # 4 ]
Newbie
Rank
Total Posts:  8
Joined  2015-01-26

Hi, Joost,

the dataset (myLib2.m_withdailyIndex) has the “key” variable.


Obs DATE vwretd PERMNO RET press_date key alpha beta
1 19970106 0.000697 11103 0.045977 01/07/1997 13521_SSAX -0.02651 2.66230
2 19970107 0.007357 11103 0.032967 01/07/1997 13521_SSAX -0.02651 2.66230
3 19970108 -0.003754 11103 -0.106383 01/07/1997 13521_SSAX -0.02651 2.66230
4 19970128 0.000521 75480 -0.016529 01/29/1997 13543_MFN -0.02009 1.64259
5 19970129 0.006684 75480 0.021008 01/29/1997 13543_MFN -0.02009 1.64259
6 19970130 0.011779 75480 0.000000 01/29/1997 13543_MFN -0.02009 1.64259
7 19970210 -0.006291 34825 -0.060241 02/10/1997 13555_OAK -0.01956 1.28220
8 19970211 0.003578 34825 0.025641 02/10/1997 13555_OAK -0.01956 1.28220
9 19970218 0.006929 70675 -0.047619 02/18/1997 13563_SVRI -0.12038 2.88638
10 19970219 -0.002864 70675 0.050000 02/18/1997 13563_SVRI -0.12038 2.88638
11 19970331 -0.021989 11197 -0.036697 04/01/1997 13605_ELSI -0.06165 1.85655
12 19970401 0.001821 11197 0.009524 04/01/1997 13605_ELSI -0.06165 1.85655
13 19970402 -0.011312 11197 -0.094340 04/01/1997 13605_ELSI -0.06165 1.85655
14 19970414 0.005163 62981 0.073059 04/15/1997 13619_SAR 0.00375 1.23712
15 19970415 0.011996 62981 0.008511 04/15/1997 13619_SAR 0.00375 1.23712
16 19970416 0.008115 62981 0.012658 04/15/1997 13619_SAR 0.00375 1.23712
17 19970415 0.011996 10187 0.000000 04/16/1997 13620_HPLX 0.00621 1.02035


Can you help me to see what the problem of the code is?

SAS CODE:
data myLib2.n_CAR (keep = key r_3day car_vw counter alpha beta );
set myLib2.m_withdailyIndex;
/* by key means that it will run through these statements for each key,
where key is a unique identifier of one observation
*/
by key;
/* retain means that the contents of these variables will be available
for example, counter will be set to zero with every observation
with every row of data (return), it will increase by 1
“if last.key then output” will write the value of the counter to the newly
created dataset
 
r_3day: 1 + 3 days of returns
car_vw: 3-day cumulative abnormal return
*/
retain counter r_3day car_vw;
if first.key then counter=0;
if first.key then car_vw=1;
if first.key then r_3day=1;
 
if ret eq . then ret = 0;
counter+1;
 
/* cumulative abnormal return */
car_vw = car_vw + ret - (alpha+beta * vwretd);
 
/* raw return, 3 day cumulative */
r_3day = r_3day + ret;
 
/* we are only interested in keeping the cumulative 3 day return (and not
cumulative 1 and 2 day) */
if last.key then output;
run;

The code to get the CARs from this example is different from what I see in other websites.
other places normally use the code like this:
data fin_ret; set fin_ret;
427 by permno descending year month;
428 if &iter; <= 12 then leadret1 = leadret1+lag&iter;(ret);
429 /* accumulative return from t+1 to t+12 month */
430 if &iter; <= 24 then leadret2 = leadret2+lag&iter;(ret);
431 /* accumulative return from t+1 to t+24 month */
432 leadret3 = leadret3+lag&iter;(ret);
433 /* accumulative return from t+1 to t+36 month */

 

Thank you for your help.

 

Profile
 
 
Posted: 28 January 2015 04:14 PM   [ Ignore ]   [ # 5 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  901
Joined  2011-09-19

hi,

Does this mean the sample code on the restatement page (http://www.wrds.us/index.php/tutorial/view/17) is broken, or did you make any changes to the code?

best regards,

Joost

 Signature 

To reply/post new questions: Please use the group WRDS/SAS on Google Groups! http://groups.google.com/d/forum/wrdssas

Profile
 
 
Posted: 28 January 2015 04:23 PM   [ Ignore ]   [ # 6 ]
Newbie
Rank
Total Posts:  8
Joined  2015-01-26

I only changed my libname and I followed everything else. All the other parts ran well until the last two steps to finish the replication.
http://www.wrds.us/index.php/tutorial/view/restatement_event_study

Any suggestion?

Profile
 
 
Posted: 28 January 2015 04:48 PM   [ Ignore ]   [ # 7 ]
Newbie
Rank
Total Posts:  8
Joined  2015-01-26
Joost Impink - 28 January 2015 04:14 PM

hi,

Does this mean the sample code on the restatement page (http://www.wrds.us/index.php/tutorial/view/17) is broken, or did you make any changes to the code?

best regards,

Joost


Hi, Joost,
I tried again and I think it worked out:)
last time I deleted the “by key;” after I posted my first question.
Now I just reran all the original code from the website and it worked out.

The code is right. Do not worry about it.

Thank you for your patience and suggestions.

Regards.

Profile
 
 
Posted: 28 January 2015 05:09 PM   [ Ignore ]   [ # 8 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  901
Joined  2011-09-19

hi,

ok smile

Yes, ‘first.something’ and ‘last.something’ will only work with ‘by.something’.

Glad it worked out.

best regards,

Joost

 Signature 

To reply/post new questions: Please use the group WRDS/SAS on Google Groups! http://groups.google.com/d/forum/wrdssas

Profile