楼主: wangbbs
40033 118

MATLAB 空间计量模型的实现   [推广有奖]

71
fenglingtt(未真实交易用户) 发表于 2017-2-23 13:56:49
wangbbs 发表于 2017-2-23 12:53
你把mprint函数找出来,仔细对照下,你的函数变量名有没有传递过来。这个错误是你修改了原函数,但是修改 ...
谢谢您,我找出来mprint函数,很长,看不明白,但是里面没有找到函数名字的地方,能不能问您的qq,我把mprint函数传给您,您帮我指出来,可以吗?

72
fenglingtt(未真实交易用户) 发表于 2017-2-23 13:56:51
wangbbs 发表于 2017-2-23 12:53
你把mprint函数找出来,仔细对照下,你的函数变量名有没有传递过来。这个错误是你修改了原函数,但是修改 ...
谢谢您,我找出来mprint函数,很长,看不明白,但是里面没有找到函数名字的地方,能不能问您的qq,我把mprint函数传给您,您帮我指出来,可以吗?

73
fenglingtt(未真实交易用户) 发表于 2017-2-23 16:00:59
% setup defaults
fid = 1; rflag = 0; cflag = 0; rnum = 0; nfmts = 1; cwidth = 80;
[nobs nvars] = size(y);
begr = 1; endr = nobs; begc = 1; endc = nvars; fmt = '%10.4f';
if nargin == 1
% rely on defaults
elseif nargin == 2
  if ~isstruct(info)
    error('mprint: you must supply the options as a structure variable');
  end;
fields = fieldnames(info);
nf = length(fields);
for i=1:nf
    if strcmp(fields{i},'fmt')
        fmts = info.fmt;
  [nfmts junk] = size(fmts);
  if nfmts == nvars
   fmt = fmts;
  elseif nfmts == 1
   fmt = fmts;
  else
   error('mprint: wrong # of formats in string -- need nvar');
  end;
    elseif strcmp(fields{i},'fid')
        fid = info.fid;
    elseif strcmp(fields{i},'begc');
        begc = info.begc;
    elseif strcmp(fields{i},'begr');
        begr = info.begr;
    elseif strcmp(fields{i},'endc');
        endc = info.endc;
    elseif strcmp(fields{i},'endr');
        endr = info.endr;
    elseif strcmp(fields{i},'width');
      cwidth = info.width;
    elseif strcmp(fields{i},'cnames');
        cnames = info.cnames;
        cflag = 1;
    elseif strcmp(fields{i},'rnames');
        rnames = info.rnames;
        rflag = 1;
    elseif strcmp(fields{i},'rflag');
        rnum = info.rflag;
    end;
end;

else
error('Wrong # of arguments to mprint');
   
end; % end of if-elseif input checking


% see if the user supplied row names and set rnum
% correct her mistake if she did this
if rflag == 1
rnum = 0;
end;

% parse formats
if nfmts == 1
   f1 = strtok(fmt,'%');
   f2 = strtok(f1,'.');
    if strcmp(f1,f2)
     f2 = strtok(f2,'d');
     dflag = 1;
     fflag = 0;
    else
     tmp1 = strtok(fmt,'f');
     tmp2 = strtok(tmp1,'.');
     tmp1 = tmp1(2:length(tmp1));
     tmp2 = tmp2(2:length(tmp2));
     opoint = num2str(str2num(tmp1) - str2num(tmp2));
     decimal = opoint(1,length(opoint));
     f2 = strtok(f2,'f');
     fflag = 1;
     dflag = 0;
    end;
   f2 = str2num(f2);
   nwide = floor(cwidth/f2); % 80 columns divided by format
   nvar = endc-begc+1;
   nsets = ceil(nvar/nwide);
else %  wrapping in this case is based on widest format in the list
nwidev = zeros(nfmts,1);
nsetsv = zeros(nfmts,1);
f2v = zeros(nfmts,1);
dflagv = zeros(nfmts,1);
fflagv = zeros(nfmts,1);
decimalv = zeros(nfmts,1);
   for ii=1:nfmts;
   f1 = strtok(fmt(ii,:),'%');
   f2 = strtok(f1,'.');
    if strcmp(f1,f2)
     f2 = strtok(f2,'d');
     dflagv(ii,1) = 1;
     fflagv(ii,1) = 0;     
    else
     tmp1 = strtok(fmt(ii,:),'f');
     tmp2 = strtok(tmp1,'.');
     tmp1 = tmp1(2:length(tmp1));
     tmp2 = tmp2(2:length(tmp2));
     opoint = num2str(str2num(tmp1) - str2num(tmp2));
     decimalv(ii,1) = opoint(1,length(opoint));     
     f2 = strtok(f2,'f');
     fflagv(ii,1) = 1;
     dflagv(ii,1) = 0;     
    end;
   f2v(ii,1) = str2num(f2);
   nwidev(ii,1) = floor(cwidth/f2v(ii,1)); % cwidth columns divided by format
   nvar = endc-begc+1;
   nsetsv(ii,1) = ceil(nvar/nwidev(ii,1));   
end;
nsets = min(nsetsv);
nwide = max(nwidev);
end;

% if we have row and column labels
% adjust variable labels and column heading strings
% to match the width of the printing format

if rnum == 1
dstr = 'Obs#';
end;

if cflag == 1 % we have column headings
[vsize nsize] = size(cnames); % error check cnames argument
if vsize ~= nvars; error('Wrong # cnames in mprint'); end;   
if nfmts == 1 % case of only 1 format string
  nmax = max(f2,nsize); % build format strings
                        % based on widest format              
  sfmt = ['%', num2str(nmax)];
  sfmt = [sfmt,'s '];
  ffmt = ['%', num2str(nmax)];
   if dflag == 1
   ffmt = [ffmt,'d '];
   elseif fflag == 1
   ffmt = [ffmt,'.'];
   ffmt = [ffmt,decimal];
   ffmt = [ffmt,'f '];
   end;
else % we have multiple format strings, process each
sfmtv = []; fmtv = [];
  for ii=1:nfmts % find and parse multiple formats
  nmax = max(f2v(ii,:),nsize); % build format strings
                        % based on widest format              
  sfmtv{ii} = ['%', num2str(nmax)];
  sfmtv{ii} = [sfmtv{ii},'s '];
  ffmtv{ii} = ['%', num2str(nmax)];
   if dflagv(ii,1) == 1
   ffmtv{ii} = [ffmtv{ii},'d '];
   elseif fflagv(ii,1) == 1
   ffmtv{ii} = [ffmtv{ii},'.'];
   ffmtv{ii} = [ffmtv{ii},decimalv(ii,1)];   
   ffmtv{ii} = [ffmtv{ii},'f '];
   end;
  end; % end of for ii loop
end; % end of if-else
elseif cflag == 0 % we have no column headings
if nfmts == 1 % case of only 1 format string
  nmax = f2; % augment format string with a space (the hard way)
  ffmt = ['%', num2str(nmax)];
   if dflag == 1
   ffmt = [ffmt,'d '];
   elseif fflag == 1
   ffmt = [ffmt,'.'];
   ffmt = [ffmt,decimal];
   ffmt = [ffmt,'f '];
   end;
else % we have multiple format strings, process each
sfmtv = []; fmtv = [];
  for ii=1:nfmts % find and parse multiple formats
  nmax = f2v(ii,:); % augment format strings with a space
  ffmtv{ii} = ['%', num2str(nmax)];
   if dflagv(ii,1) == 1
   ffmtv{ii} = [ffmtv{ii},'d '];
   elseif fflagv(ii,1) == 1
   ffmtv{ii} = [ffmtv{ii},'.'];
   ffmtv{ii} = [ffmtv{ii},decimalv(ii,1)];   
   ffmtv{ii} = [ffmtv{ii},'f '];
   end;
  end; % end of for ii loop
end; % end of if-else   
end; % end of if-elseif cflag == 0,1
   
if rflag == 1 % we have row labels
[vsize nsize] = size(rnames); % error check cnames argument
if vsize ~= nobs+1; error('Wrong # rnames in mprint'); end;  
rfmt = ['%', num2str(nsize)];
rfmt = [rfmt,'s '];
end; % end of if rflag == 1

if (rflag == 0 & cflag == 0)
    ffmt = fmt;
end;

% print matrix
for j=1:nsets;
if nfmts == 1 % print row header and column headers
if rnum == 1;fprintf(fid,'%5s ',dstr);     
     elseif rflag == 1   
  fprintf(fid,rfmt,rnames(1,:));
     end;  
     if cflag == 1
    for i = (j-1)*nwide+begc:j*nwide+begc-1
  if i <= endc
% find version #;
  %[version,junk] = version; vers = str2num(version);
   %if vers == 5.2
   fprintf(fid,sfmt,strjust(cnames(i,:),'right'));
   %else
   %fprintf(fid,sfmt,strjust(cnames(i,:)));
   %end;
  end;
end;
     end;
  fprintf(fid,'\n');
else % we have multiple formats
if rnum == 1;fprintf(fid,'%5s ',dstr);     
    elseif rflag == 1   
fprintf(fid,rfmt,rnames(1,:));
    end;
    if cflag == 1
   for i = (j-1)*nwide+begc:j*nwide+begc-1
  if i <= endc
% find version #;
  %[version,junk] = version; vers = str2num(version);
   %if vers == 5.2
   fprintf(fid,sfmtv{i},strjust(cnames(i,:),'right'));
   %else
   %fprintf(fid,sfmtv{i},strjust(cnames(i,:)));
   %end;
  end;
   end;
    end;
fprintf(fid,'\n');
end; % end of if-else nfmts
for k = begr:endr; % print row labels and numbers in matrix
  if rnum == 1; fprintf(fid,'%5d ',k);
        elseif rflag == 1        
  fprintf(fid,rfmt,rnames(k+1,:));
        end;
  for l = (j-1)*nwide+begc:j*nwide+begc-1
   if l <= endc
    if nfmts == 1
    fprintf(fid,ffmt,y(k,l));
    else
    fprintf(fid,ffmtv{l},y(k,l));
    end;
   end;
  end; % end of for l
  fprintf(fid,'\n');
end; % end of for k
fprintf(fid,'\n');
end; % end of for j

麻烦您帮看看,我需要修改什么地方可以吗?实在是麻烦了

74
kangkuaibi(真实交易用户) 发表于 2017-3-5 12:05:43
T=12; % number of time periods
N=3; % number of regions
% row-normalize W
W=normw(W1); % function of LeSage
y=A(:,[1]); % column number in the data matrix that corresponds to the dependent variable
x=A(:,[2:4]); % column numbers in the data matrix that correspond to the independent variables
for t=1:T
    t1=(t-1)*N+1;t2=t*N;
    wx(t1:t2,:)=W*x(t1:t2,:);
end
xconstant=ones(N*T,1);
[nobs K]=size(x);
% ----------------------------------------------------------------------------------------
% No fixed effects + spatially lagged dependent variable
info.lflag=0; % required for exact results
info.model=0;
info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on
% New routines to calculate effects estimates
results=sar_panel_FE(y,[xconstant x],W,T,info);
vnames=strvcat('logcit','intercept','logp','logy','logk');

我把变量改成了3个就,后面的Vnames我都改了啊,求楼主解答
提示错误Subscripted assignment dimension mismatch.

75
601585977(未真实交易用户) 发表于 2017-5-13 09:49:00
叮叮当当呀 发表于 2016-7-30 22:34
Undefined function or variable 'x'.

Error in panel_effects_sdm (line 56)
你好,请问你这个问题解决了么,我也一直这样报错,不知道怎么回事,还请大神指导

76
阮阮的火车(未真实交易用户) 发表于 2017-5-28 18:17:22
请问sdm的随机效应模型是把FE改成RE么
怎么显示错误呢
??? Reference to non-existent field 'parm'.

Error in ==> direct_indirect_effects_estimates at 21
parm=results.parm;
做固定效应的sdm时都好好的

77
wangbbs(未真实交易用户) 发表于 2017-6-5 15:09:12
阮阮的火车 发表于 2017-5-28 18:17
请问sdm的随机效应模型是把FE改成RE么
怎么显示错误呢
??? Reference to non-existent field 'parm'.
只有这段代码,不清楚整个状况。你这个错误从经验上判断是处在参数传递有误上,你好好检查下参数传递的情况吧。

78
wangbbs(未真实交易用户) 发表于 2017-6-5 15:10:25
601585977 发表于 2017-5-13 09:49
你好,请问你这个问题解决了么,我也一直这样报错,不知道怎么回事,还请大神指导
你的变量设置有误,你检查下,变量的数量和程序中的数量是不是一致。

79
拼命十三妹~(未真实交易用户) 发表于 2017-8-10 21:31:33
Wald_spatial_lag=(Rafg*btemp)'*inv(Rafg*varcov*Rafg')*Rafg*btemp
prob_spatial_lag=1-chis_cdf (Wald_spatial_lag, K)
Undefined function or variable 'k'.
楼主您好,这是做warld 空间滞后检验出的问题,您能帮我看看为什么吗、。谢谢了

80
拼命十三妹~(未真实交易用户) 发表于 2017-8-10 21:53:50
wangbbs 发表于 2015-11-3 23:13
空间和时间双固定效应的空间滞后应变量和空间自变量(物贝叶斯纠正)
% Spatial and time period fixed ef ...
楼主您好,这个 bias correction 做出来是这样的,能麻烦您告知一下是为什么吗?
>> Spatial and time period fixed effects + spatially lagged dependent variable + spatially
% independent variables
% No bias correction
info.bc=0;
info.lflag=0; % required for exact results
info.model=3;
info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on
% New routines to calculate effects estimates
Undefined function 'Spatial' for input arguments of type 'char'.

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

本版微信群
扫码
拉您进交流群
GMT+8, 2026-1-21 16:12