BookmarkSubscribeRSS Feed
Tobiasp94
Calcite | Level 5
Hi Reeza.
I have tried with the variable year since i have data for 2010-2017 and the value is numeric i had som terrible results:
My goal is to create a SUR estimation model assuming equal coefficient across time periods.

%let yvar=COPD;
%let xvars=Healthexpenditure Share_18_66 Share67_ Healthcosts Healthcosts_cofinancing Costelderlyadults Incomefromtaxes Costsports Socioeconomicindex Vocationaleducation Furthereducation Westerns Nonwesterns Dailysmokers Heavysmokers Physicalactivity Unhealthydiet Alcohol Familycontact;
%let wset=wnykom94;
%let datset=final;
%let region=Kkode;
%let time=year;

libname wcat '/folders/myfolders/sasuser.v94';

data set1; set work.&datset;
data sety; set set1; by year;if first.year;
yearch=put(year,4.);


proc iml;
print 'SUR model, assuming equal coefficients across time periods',,;
use set1;
yname={&yvar};
read all var yname into y;
xname={&xvars};
incxname={'Constant'}||xname;
read all var xname into x0;
use sety;
read all var {'year'} into year;
read all var {'yearch'} into yearch;
use wcat.&wset;
read all var _NUM_ into w;
n=ncol(w);
do i=1 to n;
w[i,]=w[i,]/sum(w[i,]);
end;
n=nrow(w);
nt=nrow(y);
t=nt/n;
xc=j(nt,1,1)||x0;
k=ncol(xc); tk=t*k;
***********OLS estimation assuming common coefficients**************;

bols=inv(t(xc)*xc)*t(xc)*y;
e=y-xc*bols;

***SUR estimate assuming time-specific coefficients***************;
b=bols;
goon=1;
iter=0;maxiter=1000;
do while (goon=1);
sigma=j(t,t,0);
do i=1 to t;
do j=i to t;
s=t(e[(i-1)*n+1:i*n])*e[(j-1)*n+1:j*n]/n;
sigma[i,j]=s; sigma[j,i]=s;
end;
end;
sigmai=inv(sigma);
kc=ncol(xc);
del1=j(kc,kc,0); del2=j(kc,1,0);
do i=1 to t;
do j=1 to t;
del1=del1+sigmai[i,j]*t(xc[(i-1)*n+1:i*n,])*xc[(j-1)*n+1:j*n,];
del2=del2+sigmai[i,j]*t(xc[(i-1)*n+1:i*n,])*y[(j-1)*n+1:j*n,];
end;
end;
del1=inv(del1);
V=del1;
b1=del1*del2;
e=y-xc*b1;
dif=max(abs(b-b1));iter=iter+1;
b=b1;
if (dif<0.0001 | iter>maxiter) then goon=0;
end;
print iter dif;
vsur=v; bsur=b;
ypred=xc*bsur;
predset=y||ypred;
create predset from predset[colname={'y' 'ypred'}];append from predset;

stdbsur=sqrt(vecdiag(Vsur));
tsur=bsur/stdbsur;
esur=y-xc*bsur;
psur=2*(1-probnorm(abs(tsur)));
resultsur= bsur||stdbsur||psur;
resultsurname={'Estimate' 'std' 'p-value'};
resultsur=round(resultsur*1000)/1000;
print 'SUR estimation results',,yname,,
resultsur[rowname=incxname colname=resultsurname];
Reeza
Super User
What does SUR stand for again? OLS is linear, which means my original answer was likely correct.
Tobiasp94
Calcite | Level 5
Seemingly unrelated regression.
PaigeMiller
Diamond | Level 26

@Tobiasp94 wrote:
Seemingly unrelated regression.

You don't have to program this yourself in PROC IML in SAS.

 

Here's a hint: type SAS seemingly unrelated regression into any search engine. It's already been programmed into SAS, so you don't have to write IML code to do this.

 

Apparently, you will need dummy variables since there is no CLASS statement for this modeling procedure. Dummy variables are easily created by PROC GLMMOD, and by several other procedures in SAS. Examples are at the links.

--
Paige Miller

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

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 18 replies
  • 2836 views
  • 2 likes
  • 4 in conversation