Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with multiy-way clustering by dyad and year following Cameron et al. (2006)

    Hey everyone,

    I am working with a replication set that estimates the impact of trade on conflict with logit and uses an undirected dyad year data set. One specification clusters the standard errors by dyad and year according to the Cameron et al. (2006) method. However, Stata issues the warning "gatt not found" every time I execute the file.
    I am using Stata 15 and the relevant code looks like this:

    Code:
    global opt ",robust cluster(dyad)"
    global trade "ltrl ztl"
    global multitrade "lopenl"
    global interactions "muldis bildis"
    global controlgrav "ldis comlng contig colony comcol fta_f gatt"
    global controlbarb   "peace votcol pol totwar diswar larea allied"
    global oldwar "con1 con2 con3 con4 con5 con6 con7 con8 con9 con10"
    global oldwar2 "con11 con12 con13 con14 con15 con16 con17 con18 con19 con20"
    global time "yr1-yr61"
    *
    //SE multi-way clustering by dyad and year following the Cameron et al. (2006) method:
    egen dyear = group(dyad year)
    matrix drop _all
    logit mid $trade $multitrade $interactions $controlbarb $controlgrav $time $oldwar $oldwar2 , robust cluster(dyad)
    matrix Vdyad = e(V)
    logit mid $trade $multitrade $interactions $controlbarb $controlgrav $time $oldwar $oldwar2 , robust cluster(year)
    matrix Vyear = e(V)
    logit mid $trade $multitrade $interactions $controlbarb $controlgrav $time $oldwar $oldwar2 , robust cluster(dyear)
    matrix Vdyear = e(V)
    mat b=e(b)
    matrix Vtot = Vdyad + Vyear - Vdyear
    matrix Bsmall = b[1,"ltrl".."gatt"]
    matrix Vtotsmall = Vtot["ltrl".."gatt","ltrl".."gatt"]
    ereturn post Bsmall Vtotsmall
    ereturn display
    The warning appears after the line
    Code:
    matrix Bsmall = b[1,"ltrl".."gatt"]
    . I am not sure how to get the code working and would appreciate any help. Thank you very much.

    Best regards

    Matthias

  • #2
    Well, the code seems to include the variable gatt. So my best guess is that the variable gatt is being omitted from the logistic regression analyses either because it is colinear with some other variable or perhaps due to perfect prediction. Without seeing the -logit- output I can't be sure of this, but flying blind, that's my best guess.

    If that's not right, please show complete output from this set of commands.

    Side issue: it is unsafe programming practice to use global macros except where there is no alternative. In this case, local macros are an easily available alternative.

    Comment


    • #3
      Dear Clyde,

      thank you for your answer. However, I think omission of "gatt" is not the reason.

      The logit output of
      Code:
      logit mid $trade $multitrade $interactions $controlbarb $controlgrav $time $oldwar $oldwar2 , robust cluster(dyear)
      immediately before Stata issues the warning, looks like this:

      Code:
       logit mid $trade $multitrade $interactions $controlba
      > rb $controlgrav $time $oldwar $oldwar2 , robust clust
      > er(dyear)
      
      note: yr1 omitted because of collinearity
      note: yr2 omitted because of collinearity
      note: yr3 omitted because of collinearity
      note: yr61 omitted because of collinearity
      Iteration 0: log pseudolikelihood = -9160.0062
      Iteration 1: log pseudolikelihood = -9121.5094
      Iteration 2: log pseudolikelihood = -7139.7451
      Iteration 3: log pseudolikelihood = -5781.7226
      Iteration 4: log pseudolikelihood = -4999.4233
      Iteration 5: log pseudolikelihood = -4646.5963
      Iteration 6: log pseudolikelihood = -4174.7558
      Iteration 7: log pseudolikelihood = -4132.5008
      Iteration 8: log pseudolikelihood = -4132.1939
      Iteration 9: log pseudolikelihood = -4132.1938
      
      Logistic regression Number of obs = 299,542
      Wald chi2(96) = 7043.42
      Prob > chi2 = 0.0000
      Log pseudolikelihood = -4132.1938 Pseudo R2 = 0.5489
      
      (Std. Err. adjusted for 299,542 clusters in dyear)
      ------------------------------------------------------------------------------
      | Robust
      mid | Coef. Std. Err. z P>|z| [95% Conf. Interval]
      -------------+----------------------------------------------------------------
      ltrl | -.2816831 .1107804 -2.54 0.011 -.4988087 -.0645574
      ztl | -.1696852 .1207617 -1.41 0.160 -.4063737 .0670033
      lopenl | 1.521421 .3482049 4.37 0.000 .838952 2.20389
      muldis | -.1927734 .0439256 -4.39 0.000 -.278866 -.1066809
      bildis | .0451235 .0140407 3.21 0.001 .0176042 .0726428
      peace | -.0196064 .0019994 -9.81 0.000 -.0235251 -.0156876
      votcol | -.8354898 .1111199 -7.52 0.000 -1.053281 -.6176988
      pol | -.1734717 .0576889 -3.01 0.003 -.2865399 -.0604034
      totwar | .2356999 .0091461 25.77 0.000 .217774 .2536258
      diswar | .0162581 .0579463 0.28 0.779 -.0973145 .1298307
      larea | .16727 .0211027 7.93 0.000 .1259095 .2086305
      allied | .0634088 .0935155 0.68 0.498 -.1198782 .2466959
      ldis | -.7705435 .1304422 -5.91 0.000 -1.026206 -.5148816
      comlng | .2389604 .090768 2.63 0.008 .0610584 .4168625
      contig | 1.180967 .125122 9.44 0.000 .9357318 1.426201
      colony | .3257941 .1476245 2.21 0.027 .0364554 .6151327
      comcol | .1246893 .1190458 1.05 0.295 -.1086362 .3580148
      fta_f | -.2837154 .1528753 -1.86 0.063 -.5833454 .0159146
      gatt | .0845778 .0611329 1.38 0.167 -.0352405 .204396
      yr1 | 0 (omitted)
      yr2 | 0 (omitted)
      yr3 | 0 (omitted)
      yr4 | 1.099007 .6407719 1.72 0.086 -.156883 2.354897
      yr5 | .3256495 .6748004 0.48 0.629 -.996935 1.648234
      yr6 | 1.386339 .5403148 2.57 0.010 .3273415 2.445337
      yr7 | 1.715505 .517751 3.31 0.001 .7007319 2.730279
      yr8 | 1.442397 .5696231 2.53 0.011 .325956 2.558837
      yr9 | .8098438 .6118651 1.32 0.186 -.3893898 2.009077
      yr10 | 1.132092 .5661676 2.00 0.046 .022424 2.24176
      yr11 | 1.398984 .5024139 2.78 0.005 .4142709 2.383697
      yr12 | 1.135468 .4931756 2.30 0.021 .1688613 2.102074
      yr13 | .7713696 .51707 1.49 0.136 -.242069 1.784808
      yr14 | .5676775 .5732175 0.99 0.322 -.5558083 1.691163
      yr15 | .5117561 .4927286 1.04 0.299 -.4539742 1.477486
      yr16 | .5446511 .4682302 1.16 0.245 -.3730632 1.462365
      yr17 | .1054876 .5270127 0.20 0.841 -.9274384 1.138414
      yr18 | .5650935 .4881192 1.16 0.247 -.3916026 1.52179
      yr19 | -.615368 .60816 -1.01 0.312 -1.80734 .5766038
      yr20 | .6322047 .4911201 1.29 0.198 -.3303731 1.594782
      yr21 | .5138907 .4967369 1.03 0.301 -.4596959 1.487477
      yr22 | .5404488 .5059239 1.07 0.285 -.4511438 1.532041
      yr23 | .49463 .5027108 0.98 0.325 -.4906651 1.479925
      yr24 | .8810904 .4640019 1.90 0.058 -.0283367 1.790517
      yr25 | .2714271 .5313844 0.51 0.609 -.7700671 1.312921
      yr26 | 1.002598 .4620235 2.17 0.030 .097049 1.908148
      yr27 | .7542277 .5052595 1.49 0.136 -.2360627 1.744518
      yr28 | 1.07989 .4504998 2.40 0.017 .1969265 1.962853
      yr29 | .3938823 .4845327 0.81 0.416 -.5557844 1.343549
      yr30 | .8211113 .4554662 1.80 0.071 -.0715859 1.713809
      yr31 | .9638972 .4594783 2.10 0.036 .0633364 1.864458
      yr32 | 1.05334 .4630383 2.27 0.023 .1458019 1.960879
      yr33 | .9768761 .4513419 2.16 0.030 .0922622 1.86149
      yr34 | .752318 .4460672 1.69 0.092 -.1219575 1.626594
      yr35 | 1.282131 .4302244 2.98 0.003 .4389071 2.125356
      yr36 | .6622246 .4556938 1.45 0.146 -.2309188 1.555368
      yr37 | .7030175 .4484018 1.57 0.117 -.1758338 1.581869
      yr38 | .4654001 .4634996 1.00 0.315 -.4430425 1.373843
      yr39 | -.1640528 .5072977 -0.32 0.746 -1.158338 .8302324
      yr40 | .2973025 .5294433 0.56 0.574 -.7403874 1.334992
      yr41 | .3105018 .4574789 0.68 0.497 -.5861403 1.207144
      yr42 | -.7175371 .4917758 -1.46 0.145 -1.6814 .2463257
      yr43 | -.2175545 .5278257 -0.41 0.680 -1.252074 .8169648
      yr44 | .9413835 .4570702 2.06 0.039 .0455424 1.837225
      yr45 | .9033584 .4466471 2.02 0.043 .0279462 1.778771
      yr46 | .916239 .4505581 2.03 0.042 .0331612 1.799317
      yr47 | .7530451 .4425851 1.70 0.089 -.1144058 1.620496
      yr48 | 1.014713 .4280599 2.37 0.018 .1757308 1.853695
      yr49 | .5301066 .4468959 1.19 0.236 -.3457933 1.406006
      yr50 | .4008088 .4492178 0.89 0.372 -.479642 1.28126
      yr51 | -.2211528 .4691557 -0.47 0.637 -1.140681 .6983755
      yr52 | .8847973 .4489987 1.97 0.049 .004776 1.764819
      yr53 | .6264586 .4886909 1.28 0.200 -.331358 1.584275
      yr54 | .8290393 .4737594 1.75 0.080 -.0995121 1.757591
      yr55 | 1.151282 .4483185 2.57 0.010 .2725941 2.02997
      yr56 | .777546 .4768046 1.63 0.103 -.1569739 1.712066
      yr57 | .4585431 .4853814 0.94 0.345 -.492787 1.409873
      yr58 | .2079696 .4973917 0.42 0.676 -.7669002 1.182839
      yr59 | .6279458 .4774949 1.32 0.188 -.3079271 1.563819
      yr60 | .560491 .4657376 1.20 0.229 -.3523379 1.47332
      yr61 | 0 (omitted)
      con1 | 2.515713 .1070426 23.50 0.000 2.305913 2.725513
      con2 | .693324 .1230568 5.63 0.000 .4521371 .9345109
      con3 | .7286335 .1364371 5.34 0.000 .4612216 .9960453
      con4 | .5031502 .1413471 3.56 0.000 .2261149 .7801855
      con5 | .105 .1566648 0.67 0.503 -.2020573 .4120574
      con6 | .3270146 .1635143 2.00 0.046 .0065324 .6474968
      con7 | .0089965 .1587087 0.06 0.955 -.3020669 .3200598
      con8 | .4167175 .1680716 2.48 0.013 .0873032 .7461318
      con9 | -.1599342 .183897 -0.87 0.384 -.5203658 .2004974
      con10 | .2357253 .1750691 1.35 0.178 -.1074038 .5788543
      con11 | -.1887196 .2035503 -0.93 0.354 -.5876708 .2102317
      con12 | .3044805 .2001996 1.52 0.128 -.0879035 .6968646
      con13 | .2346122 .1900529 1.23 0.217 -.1378846 .6071089
      con14 | -.3056957 .215135 -1.42 0.155 -.7273526 .1159612
      con15 | .016666 .2123077 0.08 0.937 -.3994493 .4327814
      con16 | .0742227 .2035501 0.36 0.715 -.3247281 .4731735
      con17 | .0747167 .2303936 0.32 0.746 -.3768464 .5262799
      con18 | .1191099 .2158417 0.55 0.581 -.3039321 .5421519
      con19 | .4443655 .2356611 1.89 0.059 -.0175218 .9062527
      con20 | .0814065 .2157455 0.38 0.706 -.3414469 .5042598
      _cons | -3.745683 1.116557 -3.35 0.001 -5.934094 -1.557272
      ------------------------------------------------------------------------------
      
      . matrix Vdyear = e(V)
      
      . //the command e(b) produces the coefficient vector
      . mat b=e(b)
      
      . //Connect all three variance covariance matrices
      . matrix Vtot = Vdyad + Vyear - Vdyear
      
      . matrix Bsmall = b[1,"ltrl".."gatt"]
      gatt not found
      r(111);
      Concerning the macros:they are used in the code of the replication set, which I simply adopted. I´ll try with locals.

      Best regards,

      Matthias

      Comment


      • #4
        Although that model looks way over-complicated for many tastes, this conversation suggests that the error is just in referencing matrix columns:


        Code:
        . sysuse auto, clear
        (1978 Automobile Data)
        
        . logit foreign mpg weight price
        
        Iteration 0:   log likelihood =  -45.03321  
        Iteration 1:   log likelihood = -22.244792  
        Iteration 2:   log likelihood = -18.069284  
        Iteration 3:   log likelihood = -17.184699  
        Iteration 4:   log likelihood = -17.161975  
        Iteration 5:   log likelihood = -17.161893  
        Iteration 6:   log likelihood = -17.161893  
        
        Logistic regression                             Number of obs     =         74
                                                        LR chi2(3)        =      55.74
                                                        Prob > chi2       =     0.0000
        Log likelihood = -17.161893                     Pseudo R2         =     0.6189
        
        ------------------------------------------------------------------------------
             foreign |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
                 mpg |  -.1210918   .0956855    -1.27   0.206     -.308632    .0664483
              weight |  -.0068497   .0019996    -3.43   0.001    -.0107688   -.0029306
               price |   .0009264   .0003074     3.01   0.003      .000324    .0015288
               _cons |   14.42237   5.414367     2.66   0.008      3.81041    25.03434
        ------------------------------------------------------------------------------
        
        . mat b = e(b)
        
        . mat li b
        
        b[1,4]
               foreign:    foreign:    foreign:    foreign:
                   mpg      weight       price       _cons
        y1  -.12109183  -.00684974   .00092639   14.422375
        
        . mat B = b[1, "weight".."price"]
        price not found
        r(111);
        
        . mat B = b[1, "foreign:weight".."foreign:price"]
        
        . mat li B
        
        B[1,2]
               foreign:    foreign:
                weight       price
        y1  -.00684974   .00092639

        Comment


        • #5
          Try this:
          Code:
          matrix Bsmall = b[1,"mid:ltrl".."mid:gatt"]
          Added: Crossed with #4 which gives the same fix.

          Comment


          • #6
            Thanks to both of you. It worked.

            Comment

            Working...
            X