BookmarkSubscribeRSS Feed
Saba1
Quartz | Level 8

Hi

I have a panel data shown below with "id" identifies different stocks and "month" is monthly dates column. The data set is sorted by id and month. 

 

data have; 
  input id month x1 x2 y;
  datalines;
45  09/30/2004  -0.30  1.34  1
45  09/30/2004  -0.30  1.34  1
45  05/31/2005  -0.08  0.78  0
45  12/31/2008    .     .    0
48  09/30/2001  -0.01  1.88  1
48  02/28/2004   0.78  1.50  0
48  05/31/2005    .    0.54  1
49  01/31/2002   0.05   .    1     
51  03/31/2001  -0.06  1.48  0
55  05/31/2005   0.30  1.21  1
55  05/31/2005   0.30  1.21  1
55  11/30/2007   .      .    0
; run;

I need to run cross sectional regression (proc reg) "by month". So the purpose is to observe variations in coefficient (beta) of "x2" over time i.e. over various months. I am using following proc but there is an Error saying "month" is not sorted in ascending order. When I sort the data by month and run the regression, resulting output gives "0" coefficients for missing values.

proc reg data=have;
 model y=x1 x2;
by month; run;
 

 Kindly guide me in this regard. I also need to know how to create a data set based on time variant coefficients of only x2 along-with their corresponding months (date), and how to ultimately draw their graph.

 

Thanks.

4 REPLIES 4
Ksharp
Super User

If I was right, you need make a new variable to flag MONTH.

 

new_month=month(month);

 

then use it as a BY variable.

 

proc reg data=have;
 model y=x1 x2; by new_month; run; 

 

But I noticed your Y variable is 0 or 1. Maybe you need check PROC LOGISTIC . 

Saba1
Quartz | Level 8
@Ksharp thanks for the reply. Can I use the same By month statement in PROC LOGISTIC? Secondly how to create a data set & graph of only x2 betas (over time)?
Ksharp
Super User

Yes. I think so.

for your second question, use OUTEST= option of PROC LOGISTIC to save the betas and use PROC SGPLOT to display it by month.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1233 views
  • 0 likes
  • 2 in conversation