Thank you very much for this helpful response, mkeintz! I have already used your code and replaced firmid by gvkey and year by houfyear (the original variable declarations). I also sorted the data accordingly by gvkey and replaced "data need / view=need;" by "data earnpred2 / view=earnpred2;". The code is actually working and runs a regression, but unfortunately, it is always the same regression and it does not adjust for the time interval properly (begyear to endyear). In the results log it shows "ERROR: UPDATE views are not supported." I have already tried to Google this but it is still not clear to me what went wrong. Do you possibly have an idea? Many thanks, Tim %macro myreg(dsn=,depvar=,regvars=,begyear=,endyear=);
%let nyears_target = %eval(1+&endyear-&begyear);
data earnpred2 / view=earnpred2;
/* For each firm, read and count qualifying years and relevant missing values */
do nyear=1 by 1 until (last.gvkey);
set &dsn (keep=gykey houfyear &depvar ®vars);
by gvkey;
where &begyear <= year <= &endyear;
total_nmiss=sum(total_nmiss,nmiss(of ®vars));
end;
label nyear = "Number of records for this firm from &begyear through &endyear" ;
/* Now reread the above records and output for qualifying FIRMID's */
do until (last.gvkey);
set &dsn (keep=gvkey year &depvar ®vars);
by gvkey;
where &begyear <= year <= &endyear;
if nyear= &nyears_target then output;
end;
run;
proc reg data=earnpred2;
model &depvar = ®vars ;
run;
quit;
%mend;
%myreg(dsn=earnpred2,depvar=earn_w, regvars=L1_earn_w L1_negE_w L1_NExE_w, begyear=2001, endyear=2010);
... View more