搜索
人大经济论坛 附件下载

附件下载

所在主题:
文件名:  Heckman.txt
资料下载链接地址: https://bbs.pinggu.org/a-1110020.html
附件大小:
我从官方网站上找到一个Heckman Two stages的宏,来自:http://support.sas.com/kb/24/979.html 。原始代码也附件了在这里。发现最后一部分/***** Estimate Consistent Standard Errors of OLS Stage *****/, 用 proc iml 部分报错,我用的是SAS 9.3 这段原代码和报的错如下:请问是版本不兼容吗?该怎么调整,谢谢啦!

。。。。
。。。。
/***** Estimate Consistent Standard Errors of OLS Stage *****/
title2 'Consistent Estimates of Standard Errors for Second Stage (OLS)';
proc iml;

/* First, calculate asymptotic variance-covariance matrix of
the probit estimates.SAS isn't very friendly and doesn't
allow us to save them from the probit estimation.
Be sure to check these estimates against those produced by
the probit procedure above.

See Greene, Econometric Analysis, pp. 677-678 for formulae.*/

usex;
read all var _all_ into x;

use h;
read all var _all_ into h;
k=ncol(x);
n=nrow(h);
invsig=J(k,k,0);
do i= 1 to n;
invsig=invsig+J(k,k,h[i,])#(x[i,]`*x[i,]);
end;
sig=inv(invsig);

prbtnm={INTERCEP %prbtrhs};
print,"Asymptotic Variance-Covariance Matrix",
"of First Stage (Probit) Coefficients",
sig[r=prbtnm c=prbtnm format=12.6];

free x h invsig;
/* Now estimate the selection-corrected standard error for the Second
Stage (OLS) */
/* Get estimate of coefficient on lambda from olsest, the dataset
containing the ols estimates; SAS is nice in that we don't need
to keep track of which element of the beta vector has the coefficient,
since it's named. */
use olsest;
read all var{lambda} into theta;

/* deltas */
use delta var{delta};
read all var{delta} into delta;

deltabar=sum(delta)/nrow(delta);

/* residuals */
use err var{e};
read all var{e} into e;

/* calculate adjusted standard error */
sigsqe=e`*e/nrow(e)+theta**2*deltabar;
sige=sqrt(sigsqe);
print,"Standard Error of Second Stage (OLS)",
"Corrected for Selection",
sige[format=12.4];

numrowe=nrow(e);
free e ;

/* calculate rho squared */
rhosq=theta**2/sigsqe;
rho=(theta/abs(theta))*sqrt(rhosq);
print,"Corrlection of Disturbance in Regression",
"and Selection Criterion (Rho)",rho[format=8.4];

use xstar;
read all var _all_ into xstar;
use w;
read all var _all_ into w;

/* Calculate Consistent Standard Errors
See Greene, Econometric Analysis, pp. 744-747 for formulae */
delcol=delta;
do i=1 to ncol(w)-1;
delcol=delcol||delta;
end;
cdeltaw=delcol#w;

free delcol;

delcol=delta;
do i=1 to ncol(xstar)-1;
delcol=delcol||delta;
end;
cdeltaxs=delcol#xstar;

free delcol;

/**** Version 1.3 (January 1993) ****/
/* cdeltaw=capdelta*w, cdeltaxs=capdelta*xstar */
/* where capdelta=diag(delta).capdelta is */
/* n x n, wherease cdelw is n x ncol(w) and */
/* cdelxstr is n x ncol(xstar).This */
/* reduces memory use. */
/***********************************************/

Q=rhosq*(xstar`*cdeltaw)*sig*(w`*cdeltaxs);

Irhosqd=1-rhosq*delta;
delcol=Irhosqd;

free delta;

do i=1 to ncol(xstar)-1;
delcol=delcol||Irhosqd;
end;
Irsdltxs=delcol#xstar;

free Irhosqd delcol;

/**** Version 1.3 (January 1993) ****/
/* Irsdltxs=(ident(nrow(capdelta))-rwhosq*capdelta)*xstar */
/* again, this is an n x nrow(xstar) matrix, rather than*/
/* needing capdelta, which is n x n. */
/**********************************************************/

asyvcov=sigsqe*inv(xstar`*xstar)*
(xstar`*Irsdltxs+ Q)*
inv(xstar`*xstar);

olsnm={INTERCEPT %olsrhs LAMBDA};
print ,"Consistent Asymptotic Covariance Matrix of Estimates",
"in Second Stage (OLS)",asyvcov[r=olsnm c=olsnm format=12.6];

asyse=sqrt(vecdiag(asyvcov));

use olsest;
read all var{INTERCEPT %olsrhs LAMBDA} into coeff;
variable=coeff`||asyse||(coeff`/asyse)||
2*(1-probt(abs(coeff`/asyse),numrowe-nrow(coeff)));
colnm={"Coeff." "Std. Err." "T-Ratio" "P Value"};
print ,,,"Parameter Estimates and ",
"Consistent Asymptotic Standard Errors of Estimates",
"in Second Stage (OLS)",variable[r=olsnm c=colnm format=12.4];

quit;

报的错如下:
NOTE: IML Ready
ERROR: (execution) Invalid argument or operand; contains missing values.

operation : `* at line 2584 column 59
operands: _TEM1003, _TEM1005
_TEM1003 1 row 27 cols (numeric)
_TEM1005 1 row 27 cols (numeric)

statement : ASSIGN at line 2584 column 25
ERROR: (execution) Matrix should be non-singular.

operation : INV at line 2584 column 80
operands: invsig
invsig 27 rows 27 cols (numeric)

statement : ASSIGN at line 2584 column 73
ERROR: Matrix sig has not been set to a value.

statement : PRINT at line 2584 column 119
ERROR: (execution) Invalid argument or operand; contains missing values.

operation : `* at line 2588 column 210
operands: e, e
e 1191 rows 1 col (numeric)
e 1191 rows 1 col (numeric)

statement : ASSIGN at line 2588 column 201
ERROR: (execution) Matrix has not been set to a value.

operation : SQRT at line 2588 column 249
operands: sigsqe

sigsqe 0 row 0 col (type ?, size 0)


statement : ASSIGN at line 2588 column 240
ERROR: Matrix sige has not been set to a value.

statement : PRINT at line 2590 column 4
ERROR: (execution) Matrix has not been set to a value.

operation : / at line 2590 column 151
operands: _TEM1001, sigsqe

_TEM1001 1 row 1 col (numeric)

7425.3869

sigsqe 0 row 0 col (type ?, size 0)


statement : ASSIGN at line 2590 column 137
ERROR: (execution) Matrix has not been set to a value.

operation : SQRT at line 2590 column 187
operands: rhosq

rhosq 0 row 0 col (type ?, size 0)


statement : ASSIGN at line 2590 column 160
ERROR: Matrix rho has not been set to a value.

statement : PRINT at line 2590 column 196
ERROR: (execution) Invalid argument or operand; contains missing values.

operation : `* at line 2592 column 111
operands: xstar, cdeltaw
xstar 1191 rows 29 cols (numeric)
cdeltaw 1191 rows 27 cols (numeric)

statement : ASSIGN at line 2592 column 96
ERROR: (execution) Matrix has not been set to a value.

operation : * at line 2592 column 156
operands: rhosq, delta

rhosq 0 row 0 col (type ?, size 0)

delta 1191 rows 1 col (numeric)

statement : ASSIGN at line 2592 column 141
ERROR: (execution) Matrix has not been set to a value.

operation : MOVE at line 2592 column 164
operands: Irhosqd

Irhosqd 0 row 0 col (type ?, size 0)


statement : ASSIGN at line 2592 column 164
ERROR: (execution) Matrix has not been set to a value.

operation : || at line 2592 column 235
operands: delcol, Irhosqd

delcol 0 row 0 col (type ?, size 0)


Irhosqd 0 row 0 col (type ?, size 0)


statement : ASSIGN at line 2592 column 222
ERROR: (execution) Matrix has not been set to a value.

operation : # at line 2594 column 17
operands: delcol, xstar

delcol 0 row 0 col (type ?, size 0)

xstar 1191 rows 29 cols (numeric)

statement : ASSIGN at line 2594 column 2
ERROR: (execution) Invalid argument or operand; contains missing values.

operation : `* at line 2594 column 79
operands: xstar, xstar
xstar 1191 rows 29 cols (numeric)
xstar 1191 rows 29 cols (numeric)

statement : ASSIGN at line 2594 column 54
ERROR: Matrix asyvcov has not been set to a value.

statement : PRINT at line 2594 column 180
ERROR: (execution) Matrix has not been set to a value.

operation : VECDIAG at line 2598 column 90
operands: asyvcov

asyvcov 0 row 0 col (type ?, size 0)


statement : ASSIGN at line 2598 column 72
ERROR: (execution) Matrix has not been set to a value.

operation : / at line 2598 column 197
operands: _TEM1003, asyse
_TEM1003 29 rows 1 col (numeric)

asyse 0 row 0 col (type ?, size 0)


statement : ASSIGN at line 2598 column 166
ERROR: Matrix variable has not been set to a value.

statement : PRINT at line 2602 column 66
NOTE: Exiting IML.




    熟悉论坛请点击新手指南
下载说明
1、论坛支持迅雷和网际快车等p2p多线程软件下载,请在上面选择下载通道单击右健下载即可。
2、论坛会定期自动批量更新下载地址,所以请不要浪费时间盗链论坛资源,盗链地址会很快失效。
3、本站为非盈利性质的学术交流网站,鼓励和保护原创作品,拒绝未经版权人许可的上传行为。本站如接到版权人发出的合格侵权通知,将积极的采取必要措施;同时,本站也将在技术手段和能力范围内,履行版权保护的注意义务。
(如有侵权,欢迎举报)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

GMT+8, 2026-1-9 09:04