楼主: kantbear
2087 1

[求助]能看懂吗? [推广有奖]

  • 1关注
  • 0粉丝

已卖:17份资源

本科生

33%

还不是VIP/贵宾

-

威望
0
论坛币
949 个
通用积分
0.8526
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
554 点
帖子
100
精华
0
在线时间
72 小时
注册时间
2008-11-28
最后登录
2024-7-14

楼主
kantbear 在职认证  发表于 2008-12-1 23:21:00 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
function ret = NeweyWestPanelStata(y, X, L, FIRM_VAR, TIME_VAR, stat) % Function that runs OLS and returns standard errors based % Newey-West autocorrelation consistent covariance estimator. % This routine can be used for a single time-series or panel data. The % routine produces identical results to Stata's newey.ado file and % % SYNTAX: ret = NeweyWestPanelStata(y, X, L, FIRM_VAR, TIME_VAR, stat) % % The value returned depends on stat: % 0: [beta, standard errors, t-statistics] % 1: residuals % Sort the data by FIRM_VAR and then TIME_VAR FIRMS = unique(FIRM_VAR); j = 0; for i=1:length(FIRMS); rows = find(FIRM_VAR==FIRMS(i)); [temp, ix] = sort(TIME_VAR(rows,:)); rows = rows(ix,:); if i==1 y2 = y(rows,:); X2 = X(rows,:); F2 = FIRM_VAR(rows,:); T2 = TIME_VAR(rows,:); else y2 = [y2; y(rows,:)]; X2 = [X2; X(rows,:)]; F2 = [F2; FIRM_VAR(rows,:)]; T2 = [T2; TIME_VAR(rows,:)]; end end % Reassign the variables after sorting. y = y2; X = X2; FIRM_VAR = F2; TIME_VAR = T2; % calculate Bhat b = pinv(X)*y; % Determine the size of the matrix of regressors [N, k] =size(X); % Generate residuals e = y - X * b; % Calculate the Newey-West autocorrelation consistent covariance % estimator. See p.464 of Greene (2000) for more information % Note that there was a typo in the 2000 edition that was corrected % in the 2003 edition. Q = 0; for l = 0:L w_l = 1-l/(L+1); for t = l+1:N if (l==0) % This calculates the S_0 portion Q = Q + e(t) ^2 * X(t, :)' * X(t,:); else % This calculates the off-diagonal terms if FIRM_VAR(t,1) == FIRM_VAR(t-l,1) Q = Q + w_l * e(t) * e(t-l)* ... (X(t, :)' * X(t-l,:) + X(t-l, :)' * X(t,:)); end end end end Q = 1/(N-k) * Q; % Calculate Newey-White standard errors varBhat = N * inv(X' * X) * Q * inv(X' * X); % calculate standard errors and t-stats se = sqrt(diag(varBhat)); t = b ./ se; if (stat==1) % return residuals ret = e; elseif (stat==0) % return SSR ret = [b se t]; end end 
二维码

扫码加我 拉你入群

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

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

关键词:correlation time-series information consistent newey-west 求助

回帖推荐

kingtobe 发表于2楼  查看完整内容

this is a function defining file. It should be saced as NeweyWestPanelStata.m

本帖被以下文库推荐

沙发
kingtobe 发表于 2008-12-5 22:38:00
this is a function defining file. It should be saced as NeweyWestPanelStata.m
已有 1 人评分论坛币 热心指数 收起 理由
crystal8832 + 10 + 1 观点有启发

总评分: 论坛币 + 10  热心指数 + 1   查看全部评分

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-25 19:07