楼主: sunhui116
118041 338

[学习分享] MATLAB空间面板数据模型操作简介   [推广有奖]

101
sunhui116(未真实交易用户) 发表于 2012-8-9 11:23:01
海瑟巫婆 发表于 2012-8-8 13:14
不明白,为什么我明明有5个解释变量,一运行就只有3个了!救命( ⊙ o ⊙ )啊!楼主  附上数据和运行代码!求 ...
我没看到运行程序,我也不知道怎么回事

102
sunhui116(未真实交易用户) 发表于 2012-8-9 11:25:08
华而不实 发表于 2012-8-8 13:20
冒失地请教楼主:您所给的权重矩阵是31×31的,但是我的面板数据是30个省域的(重庆与四川合并了),这样的话 ...
一般我们用的比较简单的权重矩阵就是二元邻接权重,相邻为1,不相邻为0,你在31*31的权重矩阵上改一下就行了。把重庆四川看成一个整体,看它跟哪些相邻

103
sunhui116(未真实交易用户) 发表于 2012-8-9 11:26:55
haoxiuqin 发表于 2012-8-9 09:19
具体如何输入及定义为空间权重矩阵呢?
"空间矩阵只需要截面n*n的矩阵,matlab空间计量程序包里给出的空间 ...
一般我们用的比较简单的权重矩阵就是二元邻接权重,相邻为1,不相邻为0,论坛里面好像有二元邻接权重矩阵,只是设置上好像和实际的不同,需要改动一些

104
华而不实(真实交易用户) 发表于 2012-8-9 14:00:15
sunhui116 发表于 2012-8-9 11:25
一般我们用的比较简单的权重矩阵就是二元邻接权重,相邻为1,不相邻为0,你在31*31的权重矩阵上改一下就行 ...
嗯,我已经把它更改过来了~~但仍然非常谢谢楼主! 由于我的数据读取遇到问题,故再次向楼主请教一下,按jplv7中所给的格式:“A=wk1read('cigardemo.wk1',1,0);W1=wk1read('Spat-Sym-US.wk1');”应该怎么对之更改从而才能读取到自己的数据呢?我的总数据矩阵名为“MPC”,空间权重矩阵名为“W2”。我输入的命令为:
“clear all;
A=wk1read('MPC');
W2=wk1read('W1');
T=20; % number of time periods
N=30; % number of regions
% row-normalize W
W=normw(W2); % function of LeSage
y=A(:,[1]); % column number in the data matrix that corresponds to the dependent variable
x=A(:,[3,4,5,7,8,9,10,11,12,13]); % column numbers in the data matrix that correspond to the independent variables
xconstant=ones(N*T,1);
[nobs K]=size(x);
% ----------------------------------------------------------------------------------------
% ols estimation
results=ols(y,[xconstant x]);
vnames=strvcat('per2','intercept','lK','lz','lrwork2','ltech','lperh','lrfdi','lopen','lurban','lgover','labor');
prt_reg(results,vnames,1);
sige=results.sige*((nobs-K)/nobs);
loglikols=-nobs/2*log(2*pi*sige)-1/(2*sige)*results.resid'*results.resid
LMsarsem_panel(results,W,y,[xconstant x]); % (Robust) LM tests
% ----------------------------------------------------------------------------------------
% spatial fixed effects + (robust) LM tests for spatial lag and spatial error model
% fixed effects, within estimator
% demeaning of the y and x variables
model=1;
[ywith,xwith,meanny,meannx,meanty,meantx]=demean(y,x,N,T,model);
results=ols(ywith,xwith);
vnames=strvcat('per2','intercept','lK','lz','lrwork2','ltech','lperh','lrfdi','lopen','lurban','lgover','labor'); % should be changed if x is changed
prt_reg(results,vnames);
FE=meanny-meannx*results.beta; % including the constant term
yme = y - mean(y);
ee=ones(T,1);
error=y-kron(ee,FE)-x*results.beta;
rsqr1 = error'*error;
rsqr2 = yme'*yme;
FE_rsqr2 = 1.0 - rsqr1/rsqr2 % r-squared including fixed effects
sige=results.sige*((nobs-K)/nobs);
loglikfe=-nobs/2*log(2*pi*sige)-1/(2*sige)*results.resid'*results.resid
LMsarsem_panel(results,W,ywith,xwith); % (Robust) LM tests
% ----------------------------------------------------------------------------------------
% spatial and time period fixed effects + (robust) LM tests for spatial lag and spatial error model
% fixed effects, within estimator
% demeaning of the y and x variables
model=3;
[ywith,xwith,meanny,meannx,meanty,meantx]=demean(y,x,N,T,model);
results=ols(ywith,xwith);
vnames=strvcat('per2','intercept','lK','lz','lrwork2','ltech','lperh','lrfdi','lopen','lurban','lgover','labor'); % should be changed if x is changed
prt_reg(results,vnames);
LMsarsem_panel(results,W,ywith,xwith); % (Robust) LM tests”
但是其结果却显示出了MPC矩阵中的所有数据!烦劳指教,十分感谢啊!

105
haoxiuqin(真实交易用户) 发表于 2012-8-9 17:55:56
非常感谢!好人!

106
haoxiuqin(真实交易用户) 发表于 2012-8-9 17:59:16
只是设置上好像和实际的不同,需要改动一些

如何改呢?

107
walkfreely(真实交易用户) 发表于 2012-8-9 19:44:42
能否给我也传一份,完整版的文件资料,感激不尽啦。
邮箱swalkfreely1@yahoo.com.cn

108
nelar570176684(真实交易用户) 发表于 2012-9-17 20:52:18
T=10;             %number of time periods
N=31;          %number of regions
W=normw(W1);  %function of Lesage将空间权重矩阵标准化
y=A(:,[1]);       % column number in the data matrix that corresponds to the dependent variable
x=A(:,[2,3,4,5,6,7,8]); % column numbers in the data matrix that correspond to the independent variables
xconstant=ones(N*T,1);
[nobs K]=size(x);
%__________________________________________________________
>> %ols estimation
>> results=ols(y,[xconstant x]);
vnames=strvcat('gy','lny0','lnp','gp','inv','sta','gov','road');
prt_reg(results,vnames,1);
sige=results.sige*((nobs-K)/nobs);
loglikols=-nobs/2*log(2*pi*sige)-1/(2*sige)*results.resid'*results.resid
LMsarsem_panel(results,W,y,[xconstant x]); % (Robust) LM tests
%moran 检验
I=eye(T);
W2=kron(I,W);
res=moran(y, [xconstant x]);
prt(res);


info.lflag=0;
info.model=1;
info.fe=0;
results=sar_panel_FE(y,x,W,T,info)
麻烦LZ帮忙看一下,怎么我的有好多问题啊,谢谢

109
sunhui116(未真实交易用户) 发表于 2012-9-18 10:44:04
nelar570176684 发表于 2012-9-17 20:52
T=10;             %number of time periods
N=31;          %number of regions
W=normw(W1);  %functio ...
results=ols(y,[xconstant x]);是包含常数项的最小二乘法回归,那么在后面定义变量名时,gy之后应该还有一个常数变量名,用“c”表示就可以。其他还有什么问题我要看到matlab结果输出窗口给出的提示才知道。
已有 1 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
Sunknownay + 100 + 6 + 1 + 1 + 1 热心帮助其他会员

总评分: 经验 + 100  论坛币 + 6  学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

110
84208544(未真实交易用户) 发表于 2012-9-19 23:46:53
一定要支持啊。

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-2-10 02:49