reverse-shooting

Matlab scripts for reverse shooting
Log | Files | Refs | README

withbetwt.m (1516B)


      1 % withbetwt.m
      2 %
      3 %     Estimates the within and between variance for a panel variable.
      4 %
      5 %     INPUTS --
      6 %          y:     (T*K)xN Matrix of Data (Stacked Vertically)
      7 %          K:     Number of variables passed in y
      8 %          year:  The year at which to evaluate the variance ratio.
      9 %                    (1=first year, etc...).
     10 %          vname: Variable name to be printed (optional)
     11 %          snam:  Country names (optional)
     12 %
     13 %     OUTPUTS --
     14 %          Var(yit) = Var(MUi) + Var(Eit)
     15 
     16 function []=withbetwt(y,K,year,vname,snam);
     17 
     18 if exist('K')~=1; K=1; end;
     19 if exist('vname')~=1; vname=vdummy('NoName',K); end;
     20 
     21 % Delete any country with missing data
     22 [TK N]=size(y);
     23 data=packr([(1:N)' y']);
     24 smpl=data(:,1);
     25 data(:,1)=[];
     26 y=data';
     27 [TK N]=size(y);
     28 fprintf('Observations Kept in the Sample: %5.0f\n',N);
     29 if exist('snam')==1; say(snam(smpl,:)); end;
     30 disp ' ';
     31 
     32 disp '----------------------------------------------------------------';
     33 disp '                           Variance Decomposition    ';
     34 disp 'Variable       Total       Between      BetwShare      WithShare';  
     35 disp '----------------------------------------------------------------';
     36 fmt='%12.6f %12.6f %12.2f %12.2f';
     37 
     38 % Now, let's run through for each variable
     39 T=TK/K;
     40 for i=1:K;
     41    beg=(i-1)*T+1;
     42    fin=beg+T-1;
     43    yi=y(beg:fin,:);
     44 
     45    vt=variance(yi(year,:)');
     46    vb=variance(panshape(yi,3)); 	% The variance of the FE
     47    cshow(vname(i,:),[vt vb vb/vt (1-vb/vt)],fmt);
     48 end;
     49 disp '----------------------------------------------------------------';
     50