Palgrave Handbook of Econometrics: Applied Econometrics

(Grace) #1
Marius Ooms 1333

Table 29.6 OLS in programming languages for applied econometrics


Software Type How to Statements/commands


GAUSS MPL begin, declarations not necessary
read data load myX[4,3]=yX.asc;
selecty y=myX[.,1] ;
add constant toX X=ones(rows(myX),1)∼myX[.,2:3];
getb b=y/X;
showb print b;


MATLAB MPL begin declarations not necessary
read data myX=load(’-ascii’,’yX.asc’);
selecty y=myX(:,1);
add constant toX X=[ones(size(myX,1), myX) myX(:,2:3)];
getb b=X\y;
showb b


Stata SPL begin, declarations not necessary
read data infile y x1 x2 using yX.mat
add constant toX added by default
getb regress y x1 x2
showb matrix list e(b)


R and SPL begin, declarations not necessary
S-PLUS read data myX<-read.table("yX.dat", header=T)
add constant toX added by default
getb b=lm(y1∼x1+x2,data=myX)$coefficients
showb b


extra line inyX.dat y1 x1 x2\\variable names

Ox EMPL begin main program main()
{
declarations decl myX, mX, vy, vb, vyhat;
read data myX=loadmat("yX.mat");
selecty vy=myX[][0];
add constant toX mX=1 So just a one: mX=1∼myX[]1:2];
is the total command;
getb olsc(vy, mX, &vb);
fity:̂y=Xb vyhat=mX*vb;
showb println("b: ",vb);
end }


extra line inyX.mat 4 3\\dimensions

Notes:MPL: matrix programming language; SPL: statistical programming language; EMPL: econometric
matrix programming language. Computation 3 × 1 regression coefficient vectorbin linear modely=Xβ+u,
whereXis a 4 × 3 matrix starting with a column of ones.yandXare read from file. myX: 4 × 3 matrix
with numerical data read from human-readable data file yX.asc. For R we read yX.dat, and for Ox we read
yX.mat, starting with an extra line as indicated.

Free download pdf