BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dmedin13
Calcite | Level 5

Hello,

I have data on multiple countries from years 1990-2017. I tried creating country fixed effects through a proc panel, however my data is not being accepted due to having multiple of the same time-series. I read that I can fix this by making a proc means of each year and add that to the proc panel, but I was not sure how to do that either. I tried different methods that did not work. I was wondering if there is an easy way I can go around this, or if you know how to add my proc means into my proc panel data. My consent error on this is that my data is not sorted in ascending sequence with respect to time-series ID. My current time period and my previous time period is the same, 2017.  Thank you in advance!

This is my code:

proc means data=All_Merged;
var year pvrated pvratem pvratef pvratea pvrates;
run;
proc sort data=All_Merged;
by id year;
run;

proc panel data=All_Merged;
id id year;
model pvrated=pvratem pvratef pvratea pvrates/POOLED;
run;
ods graphics off;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASCom1
SAS Employee

You can only have one observation for each cross section for each time period in order to run PROC PANEL. If you have multiple observations for a cross section for a time period, and you want the average of the multiple observations for the same cross section for the same time period to be used as one single observation for that cross section for that time period, then you can use PROC TIMESERIES with BY statement to accumulate the observations within the same cross section for the same time period. ACCUMULATE = AVERAGE option specifies that accumulation is based on the average values. You can also specify other methods of accumulation using the ACCUMULATE = option:

 

https://go.documentation.sas.com/doc/en/pgmsascdc/v_011/etsug/etsug_timeseries_syntax08.htm

 

Following is an example illustrating how you can achieve this:

 


data a;
do firm = 1 to 5 ;
do year =2000 to 2020;
do j = 1 to 3 ;
x = normal(1) ;
y = 2+3*x+ rannor(23);
output;
end ;
end;
end;

run;


/*each firm has 3 observations for each year */
proc print data= a; run;


/*use proc timeseries with by statement to accumulate data within each firm each year
so that each firm has only one observation for one year, ACCUMULATE = AVERAGE specifies
that the average of all observations for each firm each year is the accumulated value*/

 

proc timeseries data = a out = accumu_series;
by firm year;
id year interval = year accumulate = average ;
var y x ;
run;

 

/*each firm has one single observation for each time period*/

proc print data = accumu_series ; run;


ods graphics off;

proc panel data = accumu_series ;
id firm year ;
model y = x /fixone;
run;

 

I hope this helps. If this is not exactly what you wanted to do, then please clarify exactly what you wanted.

View solution in original post

1 REPLY 1
SASCom1
SAS Employee

You can only have one observation for each cross section for each time period in order to run PROC PANEL. If you have multiple observations for a cross section for a time period, and you want the average of the multiple observations for the same cross section for the same time period to be used as one single observation for that cross section for that time period, then you can use PROC TIMESERIES with BY statement to accumulate the observations within the same cross section for the same time period. ACCUMULATE = AVERAGE option specifies that accumulation is based on the average values. You can also specify other methods of accumulation using the ACCUMULATE = option:

 

https://go.documentation.sas.com/doc/en/pgmsascdc/v_011/etsug/etsug_timeseries_syntax08.htm

 

Following is an example illustrating how you can achieve this:

 


data a;
do firm = 1 to 5 ;
do year =2000 to 2020;
do j = 1 to 3 ;
x = normal(1) ;
y = 2+3*x+ rannor(23);
output;
end ;
end;
end;

run;


/*each firm has 3 observations for each year */
proc print data= a; run;


/*use proc timeseries with by statement to accumulate data within each firm each year
so that each firm has only one observation for one year, ACCUMULATE = AVERAGE specifies
that the average of all observations for each firm each year is the accumulated value*/

 

proc timeseries data = a out = accumu_series;
by firm year;
id year interval = year accumulate = average ;
var y x ;
run;

 

/*each firm has one single observation for each time period*/

proc print data = accumu_series ; run;


ods graphics off;

proc panel data = accumu_series ;
id firm year ;
model y = x /fixone;
run;

 

I hope this helps. If this is not exactly what you wanted to do, then please clarify exactly what you wanted.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 490 views
  • 1 like
  • 2 in conversation