WICHTIG: Der Betrieb von goMatlab.de wird privat finanziert fortgesetzt. - Mehr Infos...

Mein MATLAB Forum - goMatlab.de

Mein MATLAB Forum

 
Gast > Registrieren       Autologin?   

Partner:




Forum
      Option
[Erweitert]
  • Diese Seite per Mail weiterempfehlen
     


Gehe zu:  
Neues Thema eröffnen Neue Antwort erstellen

Geclusterte Standardfehler negativ!

 

Jazz2509
Forum-Newbie

Forum-Newbie


Beiträge: 6
Anmeldedatum: 09.05.11
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 24.08.2011, 23:54     Titel: Geclusterte Standardfehler negativ!
  Antworten mit Zitat      
Moinsen,

ich habe ein großes Problem mit meinen Standardfehlern (eigentlich kein Matlab spezielles Thema sondern Öko allgemein, aber hier kennen sich ja einige aus).

Und zwar habe ich Paneldaten (verschiedene Länder über 30 Jahre) und möchte nun die Standardfehler zweidimensional Clustern. Nachdem Paper von Cameron, Gelbach und Miller (2010): "Robust inference" berechnet man erst die Sandwich Matrix für die eine Clusterdimension, addiert dann die zweite Clusterdimension hinzu und zieht dann die White-Covariance matrix wegen Doppeltzählungen ab. Leider bekomme ich dort an einigen stellen negative Standardfehler (was lt. des Papers möglich ist). Mich würde interessieren, ob jemand damit schonmal gearbeitet hat und wie man dieses Problem umgehen, korrigieren kann.
Hier mein Code:

Code:

[N,k] = size(X);

if nargin < 3 || nargin > 4
    error('Either 1 or 2 cluster variables are required');
end
 
 
  % Calculate (X'*X)^(-1).
  xpxi = inv(X'*X);

  % Calculate the coefficient estimate b.
  b = inv(X'*X)*X'*y;

  % Calculate the regression residuals.
  e = y - X*b;
 
  % Calculate the variance robust to clustering on the first dimension
  % supplied using the function 'singlecluster'.
  varBhat = singlecluster(xpxi, X, e, g);
 
  % If two cluster variables are supplied, adjust for the second cluster
  % dimension. Follow Cameron et al. (2011, p. 241, equation (2.11)).
  if nargin == 4
      h = varargin{1};
      % Add the component attributable to the second cluster dimension.
      temp =  varBhat + singlecluster(xpxi, X, e, h);
      % Subtract the variance attributable to the intersection cluster.
      % This equals to the White heteroskedasticity-consistent covariance
      % matrix (see Thompson (2009, p. 1).
      White = N/(N-k)*xpxi*(X'*diag(e.^2)*X)*xpxi;
      varBhat = temp - White;
     
  end
 
  % Calculate standard errors and t-statistics.
  se = sqrt(diag(varBhat));
  t = b ./ se;

  % Return the calculated values.
  ret = [b se t];
 



Der Code für das Clustern der SE ist
Code:
function varB = singlecluster(xpxi, X, e, g)
  % Function that handles a single cluster dimension.
 
  % Identify unique clusters.
    G = unique(g, 'rows'); % returns the different values in the cluster
                           % vector.
    M = size(G,1);         % returns the amount of clusters.
   [N,k] = size(X);
   
    % Now calculate the "meat" of the sandwich variance estimator.
    % See "Robust Inference with Multi-way Clustering"
    % by Cameron et al. (2011, p. 240, equation (2.4)).
   
    mid = 0; % the variance estimators for each cluster are subsequently
             % added.
   
    % This code handles clusters defined by more than one variable. It
    % treats observations having the same value for ALL cluster
    % variables as members of the same cluster.
    for i=1:M % loop over all entries in G (number of clusters in
                      % the respective dimension)
      test=(1:size(g,1))';  % returns the values from 1 to the number of
                            % observations.
      for j=1:size(G,2) % for clustering in one dimension (g or h)
                        % size(G,2)=1 for the intersection (gh) size(G,2)=2.
        test2 = find(g(:,j)==G(i,j));
        test=intersect(test,test2); % returns the values common to test
                 end
      X_g = X(test,:);% chooses the rows in X that belong to a certain
                        % cluster (e.g. country).
      e_g = e(test,:);
      mid = mid + X_g'*(e_g)*(e_g)'*X_g;
      % see Cameron et al. (2011, p. 240), equation
      % (2.4). The sum of the individual sandwich variances
      % is computed as "mid" is taken as the basis for
      % the next round of the loop.
    end;
 
    % Calculate cluster-robust variance matrix estimate
    q_c = (N-1)/(N-k)*M/(M-1); % see the modification in Cameron et al.
                               %(2011, p. 241) for smaller samples.

    varB = q_c*xpxi * mid * xpxi;  


Danke schonmal für jede Hilfe!

Cameron et al. 2011.pdf
 Beschreibung:

Download
 Dateiname:  Cameron et al. 2011.pdf
 Dateigröße:  166.9 KB
 Heruntergeladen:  762 mal
Private Nachricht senden Benutzer-Profile anzeigen


Neues Thema eröffnen Neue Antwort erstellen



Einstellungen und Berechtigungen
Beiträge der letzten Zeit anzeigen:

Du kannst Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum antworten.
Du kannst deine Beiträge in diesem Forum nicht bearbeiten.
Du kannst deine Beiträge in diesem Forum nicht löschen.
Du kannst an Umfragen in diesem Forum nicht mitmachen.
Du kannst Dateien in diesem Forum posten
Du kannst Dateien in diesem Forum herunterladen
.





 Impressum  | Nutzungsbedingungen  | Datenschutz | FAQ | goMatlab RSS Button RSS

Hosted by:


Copyright © 2007 - 2025 goMatlab.de | Dies ist keine offizielle Website der Firma The Mathworks

MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.