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

Dear SAS Community,

I have a random sample of  unbalance panel data (firm_id and year) for which I would like a pooled regression. The period is from 1964 to 2017. I would like to compute the coefficients from a regression and append all of them together. So if it is year 1964 my data will have only one year, if it is 1965 my regression will have years 1964 and 1965 and so on...So if it is 1989 the regression will have the data from 1964 (start year) to 1989. Basically the moving window is  increasing every year  by 1 year, the start is 1964 and the end 2017. I would like to include in the final output all the estimated coefficients from 1964 to 2017, Could you please help. I read the fastest method is with an array statement but I am not sure how to implement it.

 

 

proc panel data = have outest=EST;
	id firm_id year;
	model Y= X/ POOLED ;
run;

 

 

 


data have; infile datalines dsd truncover; input FIRM_ID:$6. YEAR:F6. Y:32. X:32.; format YEAR F6.; datalines4; 001000,1964,0.1532485876,-0.125706215 001000,1965,0.1551261406,-0.260869565 001000,1966,0.1919831224,-0.107172996 001000,1967,0.1993450675,-0.236185018 001000,1968,0.0293626164,0.0534733827 001000,1969,0.4813189352,-0.375353699 001000,1970,0.3578391944,-0.297416428 001000,1971,0.3211850908,-0.316788786 001000,1972,0.1669070008,-0.10378374 001000,1973,0.2751091703,-0.185709487 001000,1974,0.3804762809,-0.314876922 001000,1975,0.3506045254,-0.258401792 001001,1983,-0.129190341,0.2098011364 001001,1984,-0.176821432,0.2518206083 001002,1968,0.5591404286,-0.505087992 001002,1969,0.583965501,-0.578173691 001002,1970,0.5714087198,-0.537571652 001002,1971,0.4915457535,-0.429947766 001002,1972,0.6430447138,-0.578438073 001003,1982,0.6930241855,-0.531427557 001003,1983,0.7015041311,-0.553209519 001003,1984,0.6999709218,-0.677877162 001003,1986,0.62674972,-0.5712486 001003,1987,0.6736972705,-0.707979626 001003,1988,-0.355052286,-0.129942454 001003,1989,-0.191140248,-0.002425253 001004,1965,0.2106430155,-0.155210643 001004,1966,0.6692414645,-0.583037232 001004,1967,0.499886801,-0.496490831 001004,1968,0.6275356629,-0.581206648 001004,1969,0.4878559083,-0.460292914 001004,1970,0.4498642823,-0.413619671 001004,1971,0.4744903067,-0.417498081 001004,1972,0.5699918657,-0.49594518 001004,1973,0.5548048588,-0.479156185 001004,1974,0.6861763882,-0.636374555 001004,1975,0.6015053169,-0.558693551 001004,1976,0.6394504372,-0.599018959 001004,1977,0.6240348058,-0.584545134 001004,1978,0.5816265659,-0.531832041 001004,1979,0.5123086291,-0.458362329 001004,1980,0.5233209847,-0.477335765 001004,1982,0.3317047581,-0.306853797 001004,1983,0.3644191923,-0.328308841 001004,1984,0.4125372053,-0.350541463 001004,1985,0.5276172489,-0.462554991 001004,1986,0.5291869915,-0.458297376 001004,1987,0.5464974742,-0.464838214 001004,1988,0.077088716,0.0002931367 001004,1989,0.0168717916,0.0520088279 001004,1990,-0.057490185,0.096010431 001004,1991,0.0031110177,0.0227367411 001004,1992,-0.043452877,0.0441971224 001004,1993,0.007120802,0.0171108758 001004,1994,-0.01136299,0.0361732903 001004,1995,-0.020257972,0.0573373781 001004,1996,0.027896592,0.0197037512 001004,1997,0.0213874513,0.038033801 001004,1998,0.0188177834,0.0408319848 001004,1999,0.0342212059,0.0136969314 001004,2000,-0.038204889,0.0638915149 001004,2001,-0.036293255,-0.047186614 001004,2002,-0.067500465,0.0497315331 001004,2003,-0.015857722,0.020878092 001004,2004,-0.044905315,0.0706725253 001004,2005,0.0884194433,-0.047318341 001004,2006,0.0788545248,-0.0207569 001004,2008,0.0117896523,0.0470527512 001004,2010,-0.022128896,0.0677727474 001004,2012,-0.049808969,0.0751981568 001004,2013,-0.030855087,0.0644774467 001004,2014,-0.00619195,-0.02315251 001005,1974,0.3594371367,-0.3643316 001005,1975,0.4199071002,-0.342136695 001005,1976,0.4086500947,-0.322149147 001005,1977,0.3762044407,-0.315668203 001005,1978,0.439077205,-0.405929874 001005,1979,0.3731952482,-0.318123667 001005,1980,0.2524742476,-0.177661079 001005,1981,0.4535814326,-0.378801521 001006,1974,-0.006049651,0.0154192335 001006,1975,-0.065229208,0.0670411306 001006,1976,0.1450601593,-0.034231486 001006,1977,-0.019101627,0.1331144605 001006,1978,-0.089234548,0.1197980625 001006,1979,-0.070742932,-0.037080868 001006,1980,-0.282753123,0.0287005049 001006,1981,-0.281299947,0.3196590304 001006,1982,-0.339770941,0.3426903211 001007,1974,-0.056636985,0.0079726651 001007,1975,-0.075182815,0.0781535649 001007,1976,-0.089702003,0.0353790926 001007,1977,0.3864133465,-0.426212635 001007,1978,-0.177422407,0.1815859198 001007,1979,-0.149072066,0.1370209689 001007,1980,-0.235748661,0.2384599742 001007,1981,-0.264474739,0.0987971131 001007,1982,-0.399684667,0.4239258967 001007,1983,-0.398373065,0.162693481 001007,1984,-0.632352941,0.4598425197 001008,1983,0.0571428571,-0.631818182 001008,1984,0.0533227218,-0.485475527 001008,1985,0.0515995872,-0.871001032 001009,1981,0.2076291043,-0.435752445 001009,1982,0.0607406624,-0.279731373 001009,1983,-0.075216915,0.1484201487 001009,1984,0.0413003717,0.1168210514 001009,1985,-0.003192914,0.1817900917 001009,1986,0.0089845805,0.1292646404 001009,1987,0.0078085322,0.0460259015 001009,1988,-0.023122076,0.0985667888 001009,1989,-0.042972628,0.1052333002 001009,1990,-0.022045735,0.0710324524 001009,1991,-0.074292279,0.0995375144 001009,1992,-0.093789901,0.1553878893 001009,1993,-0.001604182,0.0650543063 001009,1994,0.0329260874,0.0243967353 001010,1964,0.133240332,-0.055225146 001010,1965,0.1638142674,-0.083705013 001010,1966,0.1368568946,-0.05047219 001010,1967,0.0975890559,-0.038967899 001010,1968,0.1500266543,-0.096876117 001010,1969,0.1391677751,-0.087764409 001010,1970,0.1275110193,-0.086736119 001010,1971,0.1301049373,-0.097473838 001010,1972,0.0910515865,-0.053118073 001010,1973,0.1432410986,-0.095885158 001010,1974,0.1741219298,-0.128297939 001010,1975,0.157699844,-0.112722633 001010,1976,0.1491603249,-0.101144825 001010,1977,0.1606062086,-0.113202765 001010,1978,0.194138,-0.146072376 001010,1979,0.1884137346,-0.139162018 001010,1980,0.1798047674,-0.13770691 001010,1981,0.1876166732,-0.147170674 001010,1982,0.1204601781,-0.093356556 001010,1983,0.1063100189,-0.105756338 001010,1984,-0.082416052,0.0826882298 001010,1986,-0.106362244,0.0996050687 001010,1987,-0.344500286,0.3475634341 001010,1988,0.0250538543,-0.017420373 001010,1989,0.0965150422,0.0531635732 001010,1990,-0.063718686,0.0160599817 001010,1991,0.062201053,0.0278719711 001010,1992,-0.047355313,0.0359301774 001010,1993,0.0704168427,0.0051625338 001010,1994,-0.006319985,0.0207984956 001010,1995,-0.001252969,0.0452635151 001010,1996,0.005856792,0.0377857548 001010,1997,0.0544454527,0.0336672901 001010,1998,-0.007827789,0.0287018917 001010,1999,0.0028736053,0.0197926899 001010,2000,0.0116337542,0.0100843991 001010,2001,0.0083803341,0.0303820368 001010,2002,-0.023055376,0.0445216548 001010,2003,0.0913692499,-0.010709348 001011,1982,-0.000346574,0.0004561707 001011,1983,-0.169686985,0.1774535185 001011,1984,-0.079841075,0.0921388705 001011,1985,-0.018882526,0.0256926172 001011,1987,-0.059980931,0.0381381642 001011,1988,-0.080463213,0.138764101 001011,1990,-0.141620566,-0.101659616 001011,1991,-0.146025206,-0.029447407 001011,1992,-0.093978987,-0.072965533 001011,1993,-0.111335695,-0.03885573 001012,1974,0.042886439,-0.026205321 001012,1975,0.2881595034,-0.246402709 001012,1976,0.3212661107,-0.269332828 001012,1977,0.3665373766,-0.299365303 001012,1978,0.3040583164,-0.223592907 001012,1979,0.3206521739,-0.384881423 001012,1980,0.2300172513,-0.218516389 001012,1981,0.2830032548,-0.128978871 001012,1982,0.2593391121,-0.218418621 001012,1983,0.2499698589,-0.190652253 001012,1984,0.2215980486,-0.210510755 001012,1985,0.2729223495,-0.226804874 001012,1986,0.2708401261,-0.23990146 001012,1987,0.2932467284,-0.302607699 001012,1989,-0.082920933,0.1247462884 001013,1974,0.236974624,-0.224401804 001013,1975,0.3471174162,-0.301358286 001013,1976,0.3325549824,-0.269345642 001013,1977,0.285550812,-0.203776242 001013,1978,0.2894529047,-0.218086106 001013,1979,0.339245283,-0.179730458 001013,1980,0.4537726646,-0.341544989 001013,1981,0.3809249354,-0.299266876 001013,1982,0.3456636679,-0.257595486 001013,1983,0.2655413751,-0.171829971 001013,1984,0.3804667365,-0.329347972 001013,1985,0.2581427437,-0.148443924 001013,1986,0.1913933972,-0.043907969 001013,1987,0.1654976303,-0.004749868 001013,1988,-0.085900719,0.2369195822 001013,1990,-0.072455575,0.2131823433 001013,1992,-0.05627435,0.1424586673 001013,1993,0.0084021996,0.1130840834 001013,1994,-0.05752044,0.1893522118 001013,1995,0.0233541042,0.0945940603 001013,1997,0.0341616874,0.0935012563 001013,1998,0.0578025741,0.0733858169 001013,2001,-0.427405644,0.0293653983 001013,2002,-0.661653723,0.0332061802 001013,2003,-0.094711401,0.0318708779 001013,2006,0.0045130943,0.0553648614 001013,2007,-0.016882886,0.083999763 001013,2009,-0.334252282,0.0489493353 001013,2010,-0.042156063,0.09694475 001015,1982,0.5754482759,-0.595862069 001015,1983,0.5929810407,-0.546456905 001015,1985,0.376789549,-0.355314961 001015,1986,-0.043149862,-0.42011078 001015,1987,-0.827586207,-0.07157605 001016,1974,0.4673992674,-0.339112739 001016,1975,0.2671403574,-0.219205684 001016,1976,0.3419495169,-0.278213364 001016,1977,0.2853654429,-0.182132031 001016,1979,0.3631234116,-0.25670918 001016,1980,0.3349567224,-0.270421235 001016,1981,0.3217945035,-0.273340994 001016,1982,0.2425793469,-0.257365969 001016,1983,0.1937959577,-0.161047937 001016,1984,0.2261434371,-0.146359946 001016,1985,0.2708171475,-0.256832582 001016,1986,0.2420042262,-0.206654489 001016,1987,0.3072579972,-0.385233442 001017,1968,0.5226835732,-0.504079405 001017,1969,0.6005988024,-0.615430677 001017,1970,0.4393955316,-0.458899935 001017,1971,0.424135937,-0.408878609 001017,1972,0.244467175,-0.32917984 001017,1973,0.2783970118,-0.254038267 001017,1974,0.3956811908,-0.392676194 001017,1975,0.2937986789,-0.288159322 001017,1976,0.0794525829,-0.04541249 001017,1977,0.0062815364,0.0394655545 001017,1978,0.284773895,-0.241366949 001017,1979,0.3300118015,-0.33364462 001017,1980,0.2101953488,-0.201302326 001017,1981,0.1753279737,-0.258035136 001017,1982,0.1652188471,-0.12360721 001017,1983,0.1379634256,-0.050124913 001017,1984,0.0063422667,0.0994197042 001017,1985,0.2244873993,-0.168835287 001017,1986,0.2752189463,-0.237149801 001017,1988,0.0499045279,-0.066483661 001017,1989,-0.16791381,0.097496572 001017,1990,-0.066808274,0.0807158952 001017,1991,-0.015537482,0.1061959179 001017,1992,-0.044992385,0.0268933158 001017,1993,-0.064333652,0.0787839251 001017,1994,-0.00053188,0.0173335739 001018,1974,0.0017315854,0.0062487648 001018,1975,0.0588235294,-0.196724844 001018,1976,-0.047008004,-0.016770423 001018,1977,-0.057660377,0.1180377358 001018,1978,0.0356400356,-0.084942085 001018,1979,0.1984169815,-0.436229538 001018,1980,-0.101572432,-0.661625962 001018,1981,0.0035084642,-0.193842645 001018,1982,0.0758354756,-0.063239075 001018,1983,0.0335806326,-0.011974489 001018,1984,-0.026014452,-0.22901612 001018,1985,0.0066653597,-0.158596354 001018,1986,-0.016290119,0.0622515272 001018,1987,-0.174467668,0.0096163281 001019,1970,0.1642851441,-0.135068253 001019,1971,0.0840507621,-0.036859894 001019,1972,0.0551117716,-0.001362313 001019,1973,0.0668704385,-0.033435219 001019,1974,0.0400584439,-0.000243516 001019,1975,0.0226217407,0.0291701393 001019,1976,-0.169421731,0.2098946997 001019,1977,-0.084400023,0.1255479572 001019,1978,-0.123751135,0.1665531335 001019,1979,-0.119383187,0.1607251423 001019,1980,-0.151731213,0.1923570146 001019,1981,-0.143723831,0.2166965735 001019,1982,-0.136535289,0.2446929423 001019,1983,-0.11424976,0.2221412723 001019,1984,-0.09499131,0.1794912308 001019,1985,0.1307865169,0.1458988764 001019,1987,-0.107739477,0.1600618929 001019,1988,-0.14946917,0.2430312222 001019,1989,-0.093527943,0.1739485308 001019,1990,-0.108943314,0.1883215719 001019,1992,-0.106558979,0.1631385831 001019,1993,-0.098096395,0.1650870798 001019,1994,-0.092904309,0.1502729112 001019,1995,-0.083108512,0.1315975303 001019,1996,-0.114768079,0.1516665216 001019,1997,-0.038219764,0.0791335896 001019,1999,-0.087302129,0.1222366266 001019,2000,-0.100277687,0.1610583142 001019,2001,-0.067424421,0.1108047214 001020,1964,0.1016847088,-0.098757825 001020,1965,0.1034105404,-0.082471927 001020,1966,0.1124756627,-0.091739622 ;;;;

 

1 ACCEPTED SOLUTION

Accepted Solutions
rudfaden
Lapis Lazuli | Level 10

You can try this.

 

ods graphics off; *turn off graphics for fater excution;
ods listing close;
%macro loopOverYears;
	%do i=1965 %to 2017;
		ods output ParameterEstimates=Output&i; *save the estimates;
		proc panel data = have outest=EST;
			id firm_id year;
			model Y= X/ POOLED ;
			where year<=&i;
		run;
	
		*combine the estimates;
		%if &i = 1965 %then %do;
			data AllEstimates;
				set output&i;
				endYear=&i;
			run;
		%end;
		%else %do;
			data output&i;
				set output&i;
				endYear=&i;
			run;
			data AllEstimates;
				set AllEstimates output&i;
			run;
		%end;
	%end;
	ods listing;
%mend;

%loopOverYears;

if you need other estimates you can use ods trace to find the table name.

View solution in original post

3 REPLIES 3
rudfaden
Lapis Lazuli | Level 10

You can try this.

 

ods graphics off; *turn off graphics for fater excution;
ods listing close;
%macro loopOverYears;
	%do i=1965 %to 2017;
		ods output ParameterEstimates=Output&i; *save the estimates;
		proc panel data = have outest=EST;
			id firm_id year;
			model Y= X/ POOLED ;
			where year<=&i;
		run;
	
		*combine the estimates;
		%if &i = 1965 %then %do;
			data AllEstimates;
				set output&i;
				endYear=&i;
			run;
		%end;
		%else %do;
			data output&i;
				set output&i;
				endYear=&i;
			run;
			data AllEstimates;
				set AllEstimates output&i;
			run;
		%end;
	%end;
	ods listing;
%mend;

%loopOverYears;

if you need other estimates you can use ods trace to find the table name.

Reeza
Super User
PROC APPEND doesn't require the initial data set to exist. This can avoid the IF condition you're using.
Agent1592
Pyrite | Level 9
Thank you!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 3987 views
  • 3 likes
  • 3 in conversation