Announcement

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

  • Standard errors to reflect few clusters

    Dear StataList-ers!
    Help! I need somebody!

    I am applying a DID in multiple treatment groups and multiple time periods. I examine the before-after effect of certain policy changes (prostitution liberalization and prohibition) on sexual crime in treatment countries compared to controls.
    I look at 2 subsamples – one consists of the countries that liberalized and the controls; the other one includes the countries that implemented a ban and the controls.
    For the sake of simplicity, I’ll focus on the “liberalizing” sample. The key independent variable “Liberalization” is an indicator variable, which takes the value of one beginning in the year when a country liberalizes its policy, and zero otherwise. The dependent variable, “Rape Rate” measures the number of rape cases per 100,000 population recorded at the national level. Country and years fixed effects are included and standard errors are clustered by country. The baseline regression is:

    Code:
    reg rape_rate prostitution_liberalization controls i.year i.country, robust cluster (country)
    I have included a separate table to address the small number of clusters (using wild cluster bootstrapping).
    Code:
    reg raperate_2 prostitution_liberalization ln_gdp ln_population unemploymentrate Womenper100men police_population migrant_population GII i.year i.country, robust cluster(country)
     
    boottest prostitution_liberalization
    boottest prostitution_liberalization, nonull
    boottest prostitution_liberalization, bootcluster (country year)
    boottest prostitution_liberalization, nonull bootcluster (country year)
    However, the editor requests to “update your standard errors to reflect few clusters not just in one robustness table but in all relevant tables. This will entail your presenting this as your default method of standard-error computation when you discuss methods.”

    How to do this? Thank you – much appreciated!

    Here is also a data example:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long country int year double raperate_2 byte prostitution_liberalization double(ln_gdp ln_population unemploymentrate)
    5 2006                  0 0 10.209868431091309 13.519813537597656  4.533
    5 2007        2.475989777 0 10.354137420654297 13.538328170776367    3.9
    5 2008                  0 0 10.474204063415527 13.562336921691895  3.642
    5 2009                  0 0 10.376792907714844 13.588521957397461  5.417
    5 2010                3.3 0 10.335868835449219 13.616010665893555  6.292
    5 2011                3.4 0  10.38077163696289 13.640860557556152  7.908
    5 2012                2.2 0 10.274530410766602 13.667023658752441 11.883
    5 2013                1.6 0 10.237897872924805 13.671499252319336 15.917
    5 2014                1.2 0 10.218327522277832 13.662359237670898  16.17
    5 2015                1.7 0 10.052433967590332 13.649465560913086   14.9
    5 2016               2.59 0   10.0718355178833 13.651012420654297   12.7
    5 2017 2.3399999141693115 0 10.135930061340332 13.658625602722168   10.4
    6 1990                8.6 0   8.27312183380127  16.15366554260254    2.3
    6 1991                7.4 0 7.9651007652282715 16.148101806640625    2.3
    6 1992                6.9 0   8.11732292175293  16.14887237548828    3.3
    6 1993                7.4 0  8.276838302612305    16.150146484375    4.3
    6 1994                7.1 0  8.434235572814941 16.150951385498047    4.3
    6 1995               7.03 0  8.663568496704102 16.150869369506836      4
    6 1996               6.57 0  8.778613090515137  16.14972496032715    3.9
    6 1997               6.36 0  8.698987007141113 16.148540496826172    4.8
    6 1998  6.553398058252427 0  8.773215293884277  16.14756965637207  6.479
    6 1999  6.155339805825243 0  8.749526023864746  16.14664649963379  8.756
    6 2000 4.8543689320388355 0  8.701448440551758 16.145524978637695  8.824
    6 2001  5.496870109546166 0  8.796218872070313 16.141033172607422  8.166
    6 2002  6.401333202627194 0  8.991300582885742  16.13801383972168  7.313
    6 2003        6.333751237 0  9.187390327453613 16.137176513671875  7.812
    6 2004        6.734194859 0  9.366137504577637 16.137441635131836  8.321
    6 2005        5.831338513 0  9.498985290527344 16.137786865234375  7.927
    6 2006        5.166298267 0  9.627973556518555 16.140207290649414  7.148
    6 2007        6.176355805 0  9.818673133850098  16.14320182800293   5.32
    6 2008        5.097636113 0 10.030069351196289   16.1518611907959  4.392
    6 2009        4.597817856 0  9.890482902526856 16.159791946411133  6.662
    6 2010                5.3 0  9.893844604492188  16.16326904296875  7.279
    6 2011               6.09 0  9.985871315002441 16.165620803833008  6.711
    6 2012               6.06 0  9.889888763427734 16.167404174804687  6.978
    6 2013               5.67 0  9.899279594421387 16.168420791625977  6.953
    6 2014               6.43 0  9.890633583068848 16.168067932128906    6.1
    6 2015               5.56 0  9.782201766967773  16.17052459716797      5
    6 2016               6.15 0   9.82464599609375   16.1716365814209    3.5
    6 2017  5.650000095367432 0  9.921727180480957 16.174476623535156    2.4
    7 1990                9.5 0 10.199563026428223 15.451669692993164  7.167
    7 1991               10.3 0  10.20401382446289 15.453821182250977  7.867
    7 1992               10.8 0 10.294504165649414  15.45685863494873  8.608
    7 1993                9.6 0 10.225497245788574 15.460433959960938  9.533
    7 1994                9.2 0 10.308804512023926 15.463522911071777  7.733
    7 1995               8.42 0 10.473093032836914  15.46718692779541  6.758
    7 1996               7.37 0 10.481524467468262 15.473934173583984  6.317
    7 1997               8.23 0  10.39927864074707 15.478511810302734  5.242
    7 1998  7.885304659498208 0  10.41535758972168 15.482247352600098  4.883
    7 1999  8.967851099830796 1 10.417531967163086   15.4857759475708  5.108
    7 2000   9.31409295352324 1 10.333436012268066 15.488865852355957  4.317
    7 2001  9.199477514461654 1 10.333699226379395 15.492460250854492  4.508
    7 2002  9.304056568663938 1 10.411169052124023 15.496031761169434  4.642
    7 2003         8.76592329 1 10.608038902282715  15.49885082244873  5.433
    7 2004        10.40686779 1 10.747457504272461 15.501472473144531  5.517
    7 2005        8.764736752 1  10.79548168182373 15.504019737243652    4.8
    7 2006        9.682793877 1 10.859518051147461  15.50698184967041    3.9
    7 2007        8.995946339 1 10.976560592651367 15.510590553283691  3.767
    7 2008        7.203520557 1  11.07165813446045 15.515847206115723  3.458
    7 2009        6.371186022 1 10.971010208129883   15.5223388671875  5.992
    7 2010              16.37 1 10.968912124633789 15.526555061340332  7.475
    7 2011              15.09 1 11.030908584594727 15.531221389770508  7.567
    7 2012              14.64 1 10.976910591125488 15.534791946411133  7.542
    7 2013              14.05 1 11.021758079528809 15.538745880126953  7.008
    7 2014              13.99 1 11.043704986572266 15.543128967285156  6.533
    7 2015              16.54 1 10.878292083740234 15.548884391784668    6.2
    7 2016              29.42 1 10.888908386230469 15.557204246520996    6.1
    7 2017 31.360000610351563 1 10.938583374023438 15.564536094665527    5.3
    8 1990                3.4 0  8.141772270202637   14.2669677734375     .6
    8 1991                3.9 0  8.184234619140625 14.265151023864746    1.5
    8 1992                4.7 0   8.82204818725586  14.25690746307373    3.7
    8 1993                6.9 0  8.849539756774902 14.228483200073242    6.5
    8 1994                8.3 0  8.911251068115234 14.205491065979004    7.6
    8 1995               6.87 0  8.021053314208984 14.185745239257812    9.7
    8 1996               6.41 0  8.117531776428223 14.169816970825195     10
    8 1997               6.65 0    8.1942138671875 14.156256675720215    9.6
    8 1998   3.76947860287476 0  8.307038307189941  14.14702320098877    9.8
    8 1999 4.2547974644291715 0  8.323450088500977 14.137041091918945   12.2
    8 2000  5.332359386413441 0  8.311406135559082 14.152874946594238 14.602
    8 2001                5.5 0  8.411601066589356 14.146769523620605 13.009
    8 2002               6.56 0  8.577035903930664  14.14013385772705 11.227
    8 2003        7.914464609 0  8.878252029418945 14.134102821350098 10.342
    8 2004        8.973272256 0  9.088225364685059 14.127580642700195  10.14
    8 2005        13.30007571 0  9.243612289428711 14.122149467468262  8.031
    8 2006        11.38360671 0   9.44108772277832 14.116133689880371  5.912
    8 2007        9.084999103 0  9.716339111328125 14.110357284545898  4.592
    8 2008        11.92121567 0  9.803365707397461 14.107015609741211  5.455
    8 2009        9.242495504 0  9.597391128540039 14.104995727539063 13.549
    8 2010         6.03963792 0   9.59141731262207  14.10315990447998 16.707
    8 2011                6.9 0  9.767372131347656 14.100434303283691 12.325
    8 2012               10.8 0  9.765482902526856 14.097086906433105 10.023
    8 2013               10.2 0  9.855989456176758 14.093274116516113  8.628
    8 2014               11.2 0   9.90096378326416 14.089969635009766  7.013
    8 2015               12.3 0  9.750096321105957 14.089248657226563    6.2
    8 2016              11.55 0   9.78339672088623 14.090106964111328    6.4
    8 2017 11.399999618530273 0   9.88861083984375 14.090106964111328    5.7
    9 1990                7.6 0 10.253458976745605 15.419812202453613    3.2
    9 1991                7.5 0 10.146559715270996 15.424644470214844  6.606
    9 1992                7.3 0 10.014021873474121 15.430731773376465 11.725
    9 1993                7.2 0   9.77662181854248 15.435884475708008 16.357
    end
    label values country country
    label def country 5 "Cyprus", modify
    label def country 6 "CzechRepublic", modify
    label def country 7 "Denmark", modify
    label def country 8 "Estonia", modify
    label def country 9 "Finland", modify

    Best,

    Vanya

  • #2
    Vania:
    I think that the reviewer is correct, as with few clusters the bias with clustered standard errors is even higher than the potential one caused by their default counterparts (see, for more details,
    http://cameron.econ.ucdavis.edu/research/Cameron_Miller_JHR_2015_February.pdf).
    That said:
    1) in your baseline analysis: if you detected heteroskedasticity in your data, go -robuts- only (otherwise go default);
    2) in your sensitivity analysis (if any), bootstrapped standard errors might be reasonable (I say "might be" because I do not the customary rules in your research
    field.
    Kind regards,
    Carlo
    (StataNow 18.5)

    Comment


    • #3
      Dear Carlo,
      Thanks You for the useful suggestions!

      I do agree with the reviewer. I understand that when the number of clusters is small, the failure to control for within-cluster error correlation can lead to misleadingly small standard errors , and consequently deceptively large t-statistics and low p-values.

      My issue is not whether I should use bootstrapped errors but how to implement this. As I mentioned above, in the previous version I reported bootstrapped standard errors just in one robustness table (for the variables of interest only: prostitution_liberalization and prostitution_prohibition). The editor's request (as far as I understand ) is to report bootstrapped SEs as default (for all variables in all relevant tables). My struggle is how to do that? For instance:

      Code:
       
       reg raperate_2 prostitution_liberalization ln_gdp ln_population unemploymentrate Womenper100men police_population migrant_population GII i.year i.country, robust cluster(country)
      How to tell Stata to give the results for prostitution_liberalization, gpp, unemployment, etc. with the wild cluster bootstrapped errors and significance levels based on these? Apologies for my very rudimentary question! Best wishes, Vanya

      Comment


      • #4
        Vania:
        the following toy-example that heavily draws upon the valuable
        https://www.stata.com/bookstore/microeconometrics-stata (page 435) may be what you want:
        Code:
        . use "C:\Program Files\Stata17\ado\base\a\auto.dta"
        Code:
        (1978 automobile data)
        
        . regress price mpg, vce(boot,cluster(foreign) reps (200) seed(12345) nodots)
        
        Linear regression                                    Number of obs =        74
                                                             Replications  =       200
                                                             Wald chi2(1)  =     40.47
                                                             Prob > chi2   =    0.0000
                                                             R-squared     =    0.2196
                                                             Adj R-squared =    0.2087
                                                             Root MSE      = 2623.6529
        
                                         (Replications based on 2 clusters in foreign)
        ------------------------------------------------------------------------------
                     |   Observed   Bootstrap                         Normal-based
               price | coefficient  std. err.      z    P>|z|     [95% conf. interval]
        -------------+----------------------------------------------------------------
                 mpg |  -238.8943   37.55183    -6.36   0.000    -312.4946   -165.2941
               _cons |   11253.06   668.3663    16.84   0.000     9943.087    12563.03
        ------------------------------------------------------------------------------
        
        .


        As you know, while wild boostrap allows heteroskedastcity but not autocorrelation of the epsilon distribution), clustered boostrap allows within (but not between) cluster correlation of the epsilon distribution.
        Kind regards,
        Carlo
        (StataNow 18.5)

        Comment


        • #5
          I think you want

          Code:
          regress ...
          local vars = ustrregexra("`e(cmdline)'", "regress `e(depvar)'|i.year|i.country", "")
          foreach var of local vars{
              boottest `var', cluster(country) nograph
          }
          Then you report the coefficients from the regression and the confidence intervals and P values from the boottest results corresponding to each variable.

          Comment


          • #6
            Dear Andrew,

            Thanks a LOT for the invaluable help! You've been saving me many times! Much appreciated! Thank You!

            Yes, this is exactly what I want (I think, based on the editor's comment). I'm a bit confused though, let me clear this out. For instance, I run:

            Code:
            regress raperate_2 prostitution_dummy i.year i.country, robust cluster(country)
            local vars = ustrregexra("`e(cmdline)'", "regress `e(depvar)'|i.year|i.country", "")
            foreach var of local vars{
            boottest `var', cluster(country) nograph
            }
            This is the outcome:

            Code:
             regress raperate_2 prostitution_dummy i.year i.country, robust cluster(country)
            
            Linear regression                               Number of obs     =        841
                                                            F(27, 30)         =          .
                                                            Prob > F          =          .
                                                            R-squared         =     0.7916
                                                            Root MSE          =     4.6306
            
                                                 (Std. Err. adjusted for 31 clusters in country)
            ------------------------------------------------------------------------------------
                               |               Robust
                    raperate_2 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
            -------------------+----------------------------------------------------------------
            prostitution_dummy |  -7.086816   2.568284    -2.76   0.010    -12.33195    -1.84168
                               |
                          year |
                         1991  |   .2471276   .1957863     1.26   0.217    -.1527214    .6469766
                         1992  |   .0998559   .3901849     0.26   0.800    -.6970079    .8967198
                         1993  |   .0774797   .6499889     0.12   0.906    -1.249975    1.404934
                         1994  |   .0243636   .6118988     0.04   0.969    -1.225301    1.274028
                         1995  |   .4075931   .5388959     0.76   0.455    -.6929791    1.508165
                         1996  |   .3367318   .5282651     0.64   0.529    -.7421295    1.415593
                         1997  |   .5422653   .4723789     1.15   0.260    -.4224611    1.506992
                         1998  |   .4783048   .4618374     1.04   0.309     -.464893    1.421503
                         1999  |   1.649703   .6283181     2.63   0.013     .3665062      2.9329
                         2000  |   1.803455   .8026784     2.25   0.032     .1641673    3.442743
                         2001  |   1.598953   .7522689     2.13   0.042     .0626152    3.135291
                         2002  |   2.587786   .8228063     3.15   0.004     .9073912    4.268181
                         2003  |   3.425561   .8861091     3.87   0.001     1.615885    5.235237
                         2004  |   3.718915   .9663047     3.85   0.001     1.745458    5.692372
                         2005  |   4.508762   1.287665     3.50   0.001        1.879    7.138524
                         2006  |   4.366627   1.391763     3.14   0.004     1.524268    7.208987
                         2007  |   4.572734    1.54198     2.97   0.006     1.423591    7.721876
                         2008  |   4.774591    1.77651     2.69   0.012     1.146474    8.402707
                         2009  |   4.014829   1.780838     2.25   0.032     .3778718    7.651786
                         2010  |   4.732902   1.768522     2.68   0.012     1.121098    8.344705
                         2011  |   5.709325   1.870708     3.05   0.005     1.888829    9.529821
                         2012  |   5.263992   1.776805     2.96   0.006     1.635271    8.892712
                         2013  |   5.869567   1.835553     3.20   0.003     2.120868    9.618265
                         2014  |   5.774974   1.882848     3.07   0.005     1.929686    9.620263
                         2015  |   6.080836    1.84198     3.30   0.002     2.319012    9.842661
                         2016  |   8.016246   2.283181     3.51   0.001     3.353369    12.67912
                         2017  |   8.541717   2.507405     3.41   0.002     3.420914    13.66252
                               |
                       country |
                      Belgium  |   13.98057   .1303912   107.22   0.000     13.71428    14.24686
                     Bulgaria  |  -3.247879   3.70e-14 -8.8e+13   0.000    -3.247879   -3.247879
                      Croatia  |  -10.31367    1.65104    -6.25   0.000    -13.68554   -6.941793
                       Cyprus  |  -7.884219   3.71e-14 -2.1e+14   0.000    -7.884219   -7.884219
                CzechRepublic  |  -3.267399   3.70e-14 -8.8e+13   0.000    -3.267399   -3.267399
                      Denmark  |    .028734   .8255199     0.03   0.972    -1.657203    1.714671
                      Estonia  |  -1.442838   3.69e-14 -3.9e+13   0.000    -1.442838   -1.442838
                      Finland  |   3.154811   3.70e-14  8.5e+13   0.000     3.154811    3.154811
                       France  |   5.263415   .1834489    28.69   0.000     4.888763    5.638068
                      Germany  |  -3.345782   1.115882    -3.00   0.005    -5.624717   -1.066847
                       Greece  |  -7.646784   3.69e-14 -2.1e+14   0.000    -7.646784   -7.646784
                      Hungary  |  -7.772073   .8255199    -9.41   0.000    -9.458009   -6.086136
                      Iceland  |   17.42108   .9438805    18.46   0.000     15.49342    19.34875
                      Ireland  |  -1.482519   .0917244   -16.16   0.000    -1.669846   -1.295193
                        Italy  |  -4.455549   .2553828   -17.45   0.000    -4.977111   -3.933988
                       Latvia  |  -8.941817    1.65104    -5.42   0.000    -12.31369   -5.569944
                    Lithuania  |  -11.05145   2.568284    -4.30   0.000    -16.29659   -5.806315
                   Luxembourg  |   .2903685   3.70e-14  7.8e+12   0.000     .2903685    .2903685
                        Malta  |  -6.668484   3.70e-14 -1.8e+14   0.000    -6.668484   -6.668484
                  Netherlands  |  -1.877349   .9172443    -2.05   0.050    -3.750612   -.0040862
                       Norway  |   5.163271   .8255199     6.25   0.000     3.477334    6.849207
                       Poland  |  -4.764923   3.70e-14 -1.3e+14   0.000    -4.764923   -4.764923
                     Portugal  |  -5.549875   3.69e-14 -1.5e+14   0.000    -5.549875   -5.549875
                      Romania  |  -10.40737   2.201386    -4.73   0.000     -14.9032   -5.911537
                     Slovakia  |  -6.575744   3.72e-14 -1.8e+14   0.000    -6.575744   -6.575744
                     Slovenia  |  -8.627904   1.192418    -7.24   0.000    -11.06315   -6.192662
                        Spain  |  -7.120666   .5457285   -13.05   0.000    -8.235192    -6.00614
                       Sweden  |   24.00132   1.742764    13.77   0.000     20.44212    27.56052
                  Switzerland  |  -2.947072   3.70e-14 -8.0e+13   0.000    -2.947072   -2.947072
                UnitedKingdom  |   6.727492   .4504968    14.93   0.000     5.807455     7.64753
                               |
                         _cons |   13.37005   1.968411     6.79   0.000     9.350023    17.39009
            ------------------------------------------------------------------------------------
            
            .
            . local vars = ustrregexra("`e(cmdline)'", "regress `e(depvar)'|i.year|i.country", "")
            
            .
            . foreach var of local vars{
              2.
            .     boottest `var', cluster(country) nograph
              3.
            . }
            
            Overriding estimator's cluster/robust settings with cluster(country)
            
            Wild bootstrap-t, null imposed, 999 replications, Wald test, clustering by country, bootstrap clustering by country, Rademacher we
            > ights:
              prostitution_dummy
            
                                       t(30) =    -2.7594
                                    Prob>|t| =     0.0080
            
            95% confidence set for null hypothesis expression: [-13.33, -1.148]
            invalid 'cluster'
            r(198);
            So, I should report the coefficient (-7.086816, this is anyway my originally reported coefficient) AND the P-value from the boottest (0.0080). In the previous version I reported t-stats. What should I do about this? The t-stats with the boottest are the same, should I report P-values in the previous-version tables as well (for the sake of consistency)?

            Isn't there a way to outreg2 the results (with sig. levels and all)??

            Another question: why do I get this "invalid 'cluster' r(198)" in the end?

            Thanks heaps! All the very best,

            Vanya
            Last edited by Vania Stef; 18 Feb 2022, 04:47.

            Comment


            • #7
              Originally posted by Vania Stef View Post
              So, I should report the coefficient (-7.086816, this is anyway my originally reported coefficient) AND the P-value from the boottest (0.0080). In the previous version I reported t-stats. What should I do about this? The t-stats with the boottest are the same, should I report P-values in the previous-version tables as well (for the sake of consistency)?
              Yes, report the coefficient from the regression and if reporting the Wild-bootstrap t statistic, use its P-value. Otherwise report the coefficient and the Wild-bootstrap confidence intervals.


              Isn't there a way to outreg2 the results (with sig. levels and all)??
              I could help you with estout, outreg2 will be too much of a hassle to figure out.


              Another question: why do I get this "invalid 'cluster' r(198)" in the end?
              I am parsing the command line to get the list of variables, and your inclusion of the option -cluster(country)- messes up my code. You do not need to include this as boottest will do the clustering for you. Consider the following:


              Code:
              webuse grunfeld, clear
              qui regress invest mvalue kstock i.company i.year, cluster(company)
              local vars = ustrregexra("`e(cmdline)'", "regress `e(depvar)'|i.year|i.company", "")
              di "`vars'"
              qui regress invest mvalue kstock i.company i.year
              local vars = ustrregexra("`e(cmdline)'", "regress `e(depvar)'|i.year|i.company", "")
              di "`vars'"
              Res.:

              Code:
              . di "`vars'"
               mvalue kstock  , cluster(company)
              
              .
              . qui regress invest mvalue kstock i.company i.year
              
              .
              . local vars = ustrregexra("`e(cmdline)'", "regress `e(depvar)'|i.year|i.company", "")
              
              .
              . di "`vars'"
               mvalue kstock  

              In this case, an iteration of the loop encounters ", cluster(company)" as one of the variables and throws in the error. So change the code to

              Code:
              regress raperate_2 prostitution_dummy i.year i.country, robust cluster(country)
              local vars = ustrregexra("`e(cmdline)'", "regress `e(depvar)'|i.year|i.country|robust|\,|cluster\(|country|\)", "")
              foreach var of local vars{
                  boottest `var', cluster(country) nograph
              }
              to get rid of the error.

              Comment


              • #8
                Dear Andrew,

                Thanks again for your absolutely invaluable help! That was so useful! Thank you for the example too - I got it! Thanks for the updated code too.

                I could help you with estout, outreg2 will be too much of a hassle to figure out.
                I was trying with outreg2, but gave up. If it's not too much of a bother, please help with estout (coefficient and p values, with sig.*, adjusted R-squared). Thank You!

                Have a good weekend,

                Vanya

                Comment


                • #9
                  You need first to install estout:

                  Code:
                  ssc install estout, replace
                  Below, save each regression with a different suffix. I use \(1, 2, 3,\cdots\) where my models have the prefix "m". Make sure that you change the highlighted for each model. I set the seed before running boottest so that the results are replicable across iterations of the code, but you do not need to do this.

                  Code:
                  * Example generated by -dataex-. To install: ssc install dataex
                  clear
                  input long country int year double raperate_2 byte prostitution_liberalization double(ln_gdp ln_population unemploymentrate)
                  5 2006                  0 0 10.209868431091309 13.519813537597656  4.533
                  5 2007        2.475989777 0 10.354137420654297 13.538328170776367    3.9
                  5 2008                  0 0 10.474204063415527 13.562336921691895  3.642
                  5 2009                  0 0 10.376792907714844 13.588521957397461  5.417
                  5 2010                3.3 0 10.335868835449219 13.616010665893555  6.292
                  5 2011                3.4 0  10.38077163696289 13.640860557556152  7.908
                  5 2012                2.2 0 10.274530410766602 13.667023658752441 11.883
                  5 2013                1.6 0 10.237897872924805 13.671499252319336 15.917
                  5 2014                1.2 0 10.218327522277832 13.662359237670898  16.17
                  5 2015                1.7 0 10.052433967590332 13.649465560913086   14.9
                  5 2016               2.59 0   10.0718355178833 13.651012420654297   12.7
                  5 2017 2.3399999141693115 0 10.135930061340332 13.658625602722168   10.4
                  6 1990                8.6 0   8.27312183380127  16.15366554260254    2.3
                  6 1991                7.4 0 7.9651007652282715 16.148101806640625    2.3
                  6 1992                6.9 0   8.11732292175293  16.14887237548828    3.3
                  6 1993                7.4 0  8.276838302612305    16.150146484375    4.3
                  6 1994                7.1 0  8.434235572814941 16.150951385498047    4.3
                  6 1995               7.03 0  8.663568496704102 16.150869369506836      4
                  6 1996               6.57 0  8.778613090515137  16.14972496032715    3.9
                  6 1997               6.36 0  8.698987007141113 16.148540496826172    4.8
                  6 1998  6.553398058252427 0  8.773215293884277  16.14756965637207  6.479
                  6 1999  6.155339805825243 0  8.749526023864746  16.14664649963379  8.756
                  6 2000 4.8543689320388355 0  8.701448440551758 16.145524978637695  8.824
                  6 2001  5.496870109546166 0  8.796218872070313 16.141033172607422  8.166
                  6 2002  6.401333202627194 0  8.991300582885742  16.13801383972168  7.313
                  6 2003        6.333751237 0  9.187390327453613 16.137176513671875  7.812
                  6 2004        6.734194859 0  9.366137504577637 16.137441635131836  8.321
                  6 2005        5.831338513 0  9.498985290527344 16.137786865234375  7.927
                  6 2006        5.166298267 0  9.627973556518555 16.140207290649414  7.148
                  6 2007        6.176355805 0  9.818673133850098  16.14320182800293   5.32
                  6 2008        5.097636113 0 10.030069351196289   16.1518611907959  4.392
                  6 2009        4.597817856 0  9.890482902526856 16.159791946411133  6.662
                  6 2010                5.3 0  9.893844604492188  16.16326904296875  7.279
                  6 2011               6.09 0  9.985871315002441 16.165620803833008  6.711
                  6 2012               6.06 0  9.889888763427734 16.167404174804687  6.978
                  6 2013               5.67 0  9.899279594421387 16.168420791625977  6.953
                  6 2014               6.43 0  9.890633583068848 16.168067932128906    6.1
                  6 2015               5.56 0  9.782201766967773  16.17052459716797      5
                  6 2016               6.15 0   9.82464599609375   16.1716365814209    3.5
                  6 2017  5.650000095367432 0  9.921727180480957 16.174476623535156    2.4
                  7 1990                9.5 0 10.199563026428223 15.451669692993164  7.167
                  7 1991               10.3 0  10.20401382446289 15.453821182250977  7.867
                  7 1992               10.8 0 10.294504165649414  15.45685863494873  8.608
                  7 1993                9.6 0 10.225497245788574 15.460433959960938  9.533
                  7 1994                9.2 0 10.308804512023926 15.463522911071777  7.733
                  7 1995               8.42 0 10.473093032836914  15.46718692779541  6.758
                  7 1996               7.37 0 10.481524467468262 15.473934173583984  6.317
                  7 1997               8.23 0  10.39927864074707 15.478511810302734  5.242
                  7 1998  7.885304659498208 0  10.41535758972168 15.482247352600098  4.883
                  7 1999  8.967851099830796 1 10.417531967163086   15.4857759475708  5.108
                  7 2000   9.31409295352324 1 10.333436012268066 15.488865852355957  4.317
                  7 2001  9.199477514461654 1 10.333699226379395 15.492460250854492  4.508
                  7 2002  9.304056568663938 1 10.411169052124023 15.496031761169434  4.642
                  7 2003         8.76592329 1 10.608038902282715  15.49885082244873  5.433
                  7 2004        10.40686779 1 10.747457504272461 15.501472473144531  5.517
                  7 2005        8.764736752 1  10.79548168182373 15.504019737243652    4.8
                  7 2006        9.682793877 1 10.859518051147461  15.50698184967041    3.9
                  7 2007        8.995946339 1 10.976560592651367 15.510590553283691  3.767
                  7 2008        7.203520557 1  11.07165813446045 15.515847206115723  3.458
                  7 2009        6.371186022 1 10.971010208129883   15.5223388671875  5.992
                  7 2010              16.37 1 10.968912124633789 15.526555061340332  7.475
                  7 2011              15.09 1 11.030908584594727 15.531221389770508  7.567
                  7 2012              14.64 1 10.976910591125488 15.534791946411133  7.542
                  7 2013              14.05 1 11.021758079528809 15.538745880126953  7.008
                  7 2014              13.99 1 11.043704986572266 15.543128967285156  6.533
                  7 2015              16.54 1 10.878292083740234 15.548884391784668    6.2
                  7 2016              29.42 1 10.888908386230469 15.557204246520996    6.1
                  7 2017 31.360000610351563 1 10.938583374023438 15.564536094665527    5.3
                  8 1990                3.4 0  8.141772270202637   14.2669677734375     .6
                  8 1991                3.9 0  8.184234619140625 14.265151023864746    1.5
                  8 1992                4.7 0   8.82204818725586  14.25690746307373    3.7
                  8 1993                6.9 0  8.849539756774902 14.228483200073242    6.5
                  8 1994                8.3 0  8.911251068115234 14.205491065979004    7.6
                  8 1995               6.87 0  8.021053314208984 14.185745239257812    9.7
                  8 1996               6.41 0  8.117531776428223 14.169816970825195     10
                  8 1997               6.65 0    8.1942138671875 14.156256675720215    9.6
                  8 1998   3.76947860287476 0  8.307038307189941  14.14702320098877    9.8
                  8 1999 4.2547974644291715 0  8.323450088500977 14.137041091918945   12.2
                  8 2000  5.332359386413441 0  8.311406135559082 14.152874946594238 14.602
                  8 2001                5.5 0  8.411601066589356 14.146769523620605 13.009
                  8 2002               6.56 0  8.577035903930664  14.14013385772705 11.227
                  8 2003        7.914464609 0  8.878252029418945 14.134102821350098 10.342
                  8 2004        8.973272256 0  9.088225364685059 14.127580642700195  10.14
                  8 2005        13.30007571 0  9.243612289428711 14.122149467468262  8.031
                  8 2006        11.38360671 0   9.44108772277832 14.116133689880371  5.912
                  8 2007        9.084999103 0  9.716339111328125 14.110357284545898  4.592
                  8 2008        11.92121567 0  9.803365707397461 14.107015609741211  5.455
                  8 2009        9.242495504 0  9.597391128540039 14.104995727539063 13.549
                  8 2010         6.03963792 0   9.59141731262207  14.10315990447998 16.707
                  8 2011                6.9 0  9.767372131347656 14.100434303283691 12.325
                  8 2012               10.8 0  9.765482902526856 14.097086906433105 10.023
                  8 2013               10.2 0  9.855989456176758 14.093274116516113  8.628
                  8 2014               11.2 0   9.90096378326416 14.089969635009766  7.013
                  8 2015               12.3 0  9.750096321105957 14.089248657226563    6.2
                  8 2016              11.55 0   9.78339672088623 14.090106964111328    6.4
                  8 2017 11.399999618530273 0   9.88861083984375 14.090106964111328    5.7
                  9 1990                7.6 0 10.253458976745605 15.419812202453613    3.2
                  9 1991                7.5 0 10.146559715270996 15.424644470214844  6.606
                  9 1992                7.3 0 10.014021873474121 15.430731773376465 11.725
                  9 1993                7.2 0   9.77662181854248 15.435884475708008 16.357
                  end
                  label values country country
                  label def country 5 "Cyprus", modify
                  label def country 6 "CzechRepublic", modify
                  label def country 7 "Denmark", modify
                  label def country 8 "Estonia", modify
                  label def country 9 "Finland", modify
                  replace ln_gdp = runiformint(3,5)
                  
                  eststo m1: reg raperate_2 prostitution_liberalization ln_gdp i.country, robust cluster(country)
                  local vars = ustrregexra("`e(cmdline)'", "regress `e(depvar)'|i.year|i.country|robust|\,|cluster\(|country|\)", "")
                  local pvals
                  local tstat
                  set seed 02202022
                  foreach var of local vars{
                      boottest `var', cluster(country) nograph
                      local pvals= "`pvals' `=r(p)'"
                      local tstat= "`tstat' `=r(t)'"
                  }
                  di "`pvals'"
                  di "`tstat'"
                  foreach stat in pvals tstat{
                      local `stat'= "("+ ustrregexra(trim("``stat''"), " ", ",") + ")"
                      mat `stat'= ``stat''
                      mat colnames `stat'= `vars'
                      estadd matrix `stat': m1
                  }
                  
                  eststo m2: reg raperate_2 prostitution_liberalization ln_gdp ln_population unemploymentrate i.country i.year, robust cluster(country)
                  local vars = ustrregexra("`e(cmdline)'", "regress `e(depvar)'|i.year|i.country|robust|\,|cluster\(|country|\)", "")
                  local pvals
                  local tstat
                  set seed 02202022
                  foreach var of local vars{
                      boottest `var', cluster(country) nograph
                      local pvals= "`pvals' `=r(p)'"
                      local tstat= "`tstat' `=r(t)'"
                  }
                  di "`pvals'"
                  di "`tstat'"
                  foreach stat in pvals tstat{
                      local `stat'= "("+ ustrregexra(trim("``stat''"), " ", ",") + ")"
                      mat `stat'= ``stat''
                      mat colnames `stat'= `vars'
                      estadd matrix `stat': m2
                  }
                  
                  esttab m1 m2 using myfile.rtf,  cells(b(fmt(3) pvalue(pvals) star)  tstat(par fmt(2))) ///
                  indicate("country effects= *.country" "year effects =*.year") ///
                  drop(_cons) nomtitles collab(none) starlevels( * 0.10 ** 0.05 *** 0.010) replace ///
                  addnotes("Some description of the dependent variables and models HERE." ///
                  "Wild cluster t-statistics in parentheses." "* p<0.10, ** p<0.05, *** p<0.01") ///
                   varwidth(30) stats(N r2_a, labels(Observations "Adjusted R-squared") fmt(a3))
                  The above will be saved as a rtf file which you can open in a word processor. If you want a LaTex file, save with the extension .tex.

                  Res.:

                  Code:
                  . esttab m1 m2,  cells(b(fmt(3) pvalue(pvals) star)  tstat(par fmt(2))) ///
                  > indicate("country effects= *.country" "year effects =*.year") ///
                  > drop(_cons) nomtitles collab(none) starlevels( * 0.10 ** 0.05 *** 0.010) replace ///
                  > addnotes("Some description of the dependent variables and models HERE." ///
                  > "Wild cluster t-statistics in parentheses." "* p<0.10, ** p<0.05, *** p<0.01") ///
                  >  varwidth(30) stats(N r2_a, labels(Observations "Adjusted R-squared") fmt(a3))
                  
                  --------------------------------------------------------------
                                                          (1)             (2)  
                  --------------------------------------------------------------
                  prostitution_liberalization           3.480           4.981  
                                                      (11.30)          (1.62)  
                  ln_gdp                                1.144***        0.632***
                                                       (1.83)          (3.30)  
                  ln_population                                       -19.099  
                                                                      (-1.41)  
                  unemploymentrate                                      0.074  
                                                                       (0.32)  
                  country effects                         Yes             Yes  
                  year effects                             No             Yes  
                  --------------------------------------------------------------
                  Observations                            100             100  
                  Adjusted R-squared                    0.494           0.509  
                  --------------------------------------------------------------
                  Some description of the dependent variables and models HERE.
                  Wild cluster t-statistics in parentheses.
                  * p<0.10, ** p<0.05, *** p<0.01
                  If you want to report the p-values in addition, which is unconventional as the significance stars already indicate them, you can change the esttab command to:

                  Code:
                  esttab m1 m2 using myfile.rtf, cells(b(fmt(3) pvalue(pvals) star) tstat(par fmt(2)) ///
                  pvals(par([ ] ))) indicate("country effects= *.country" "year effects =*.year") ///
                  drop(_cons) nomtitles collab(none) starlevels( * 0.10 ** 0.05 *** 0.010) replace ///
                  addnotes("Some description of the dependent variables and models HERE." ///
                  "Wild cluster t-statistics and p-values in parentheses and brackets, respectively." "* p<0.10, ** p<0.05, *** p<0.01") ///
                  varwidth(30) stats(N r2_a, labels(Observations "Adjusted R-squared") fmt(a3))
                  Res.:

                  Code:
                  . esttab m1 m2, cells(b(fmt(3) pvalue(pvals) star) tstat(par fmt(2)) ///
                  > pvals(par([ ] ))) indicate("country effects= *.country" "year effects =*.year") ///
                  > drop(_cons) nomtitles collab(none) starlevels( * 0.10 ** 0.05 *** 0.010) replace ///
                  > addnotes("Some description of the dependent variables and models HERE." ///
                  > "Wild cluster t-statistics and p-values in parentheses and brackets, respectively." "* p<0.10, ** p<0.05, *** p<0.01") ///
                  > varwidth(30) stats(N r2_a, labels(Observations "Adjusted R-squared") fmt(a3))
                  
                  --------------------------------------------------------------
                                                          (1)             (2)   
                  --------------------------------------------------------------
                  prostitution_liberalization           3.480           4.981   
                                                      (11.30)          (1.62)   
                                                      [0.938]         [0.563]   
                  ln_gdp                                1.144***        0.632***
                                                       (1.83)          (3.30)   
                                                      [0.000]         [0.000]   
                  ln_population                                       -19.099   
                                                                      (-1.41)   
                                                                      [0.125]   
                  unemploymentrate                                      0.074   
                                                                       (0.32)   
                                                                      [0.813]   
                  country effects                         Yes             Yes   
                  year effects                             No             Yes   
                  --------------------------------------------------------------
                  Observations                            100             100   
                  Adjusted R-squared                    0.494           0.509   
                  --------------------------------------------------------------
                  Some description of the dependent variables and models HERE.
                  Wild cluster t-statistics and p-values in parentheses and brackets, respectively.
                  * p<0.10, ** p<0.05, *** p<0.01
                  Last edited by Andrew Musau; 20 Feb 2022, 09:12.

                  Comment


                  • #10
                    Dear Andrew, Thank You! You are a savior! Great - I went through your example, it is super useful! You have the talent to make it all look so simple. Thanks!

                    When I run the code, however, I get to this point:

                    Code:
                    esttab m1 m2 using myfile.rtf,  cells(b(fmt(3) pvalue(pvals) star)  tstat(par fmt(2))) ///
                    option / not allowed
                    r(198);
                    
                    . 
                    . indicate("country effects= *.country" "year effects =*.year") ///
                    command indicate is unrecognized
                    r(199);
                    
                    . 
                    . drop(_cons) nomtitles collab(none) starlevels( * 0.10 ** 0.05 *** 0.010) replace ///
                    variable _cons not found
                    r(111);
                    
                    . 
                    . addnotes("Some description of the dependent variables and models HERE." ///
                    command addnotes is unrecognized
                    r(199);
                    
                    . 
                    . "Wild cluster t-statistics in parentheses." "* p<0.10, ** p<0.05, *** p<0.01") ///
                    "Wild cluster t-statistics in parentheses. is not a valid command name
                    r(199);
                    
                    
                    .  varwidth(30) stats(N r2_a, labels(Observations "Adjusted R-squared") fmt(a3))
                    command varwidth is unrecognized
                    r(199);
                    
                    .
                    If I delete the /// from

                    Code:
                    esttab m1 m2 using myfile.rtf,  cells(b(fmt(3) pvalue(pvals) star)  tstat(par fmt(2)))
                    I end up here:

                    Code:
                    . esttab m1 m2 using myfile.rtf,  cells(b(fmt(3) pvalue(pvals) star)  tstat(par fmt(2))) 
                    (output written to myfile.rtf)
                    
                    . 
                    . indicate("country effects= *.country" "year effects =*.year") 
                    command indicate is unrecognized
                    r(199);
                    
                    . 
                    . drop(_cons) nomtitles collab(none) starlevels( * 0.10 ** 0.05 *** 0.010) replace ///
                    variable _cons not found
                    r(111);
                    
                    . 
                    . addnotes("Some description of the dependent variables and models HERE." ///
                    command addnotes is unrecognized
                    r(199);
                    
                    . 
                    . "Wild cluster t-statistics in parentheses." "* p<0.10, ** p<0.05, *** p<0.01") ///
                    "Wild cluster t-statistics in parentheses. is not a valid command name
                    r(199);
                    
                    . 
                    .  varwidth(30) stats(N r2_a, labels(Observations "Adjusted R-squared") fmt(a3))
                    command varwidth is unrecognized
                    r(199);

                    What am I doing wrong?

                    As for this option, I added a ) ... I am still getting stuck.

                    Code:
                     
                     esttab m1 m2 using myfile.rtf, cells(b(fmt(3) pvalue(pvals) star) tstat(par fmt(2))) /// pvals(par([ ] ))) indicate("country effects= *.country" "year effects =*.year") /// drop(_cons) nomtitles collab(none) starlevels( * 0.10 ** 0.05 *** 0.010) replace /// addnotes("Some description of the dependent variables and models HERE." /// "Wild cluster t-statistics and p-values in parentheses and brackets, respectively." "* p<0.10, ** p<0.05, *** p<0.01") /// varwidth(30) stats(N r2_a, labels(Observations "Adjusted R-squared") fmt(a3))

                    This is the output:

                    Code:
                     esttab m1 m2 using myfile.rtf, cells(b(fmt(3) pvalue(pvals) star) tstat(par fmt(2))) ///
                    option / not allowed
                    r(198);
                    
                    . 
                    . pvals(par([ ] ))) indicate("country effects= *.country" "year effects =*.year") ///
                    command pvals is unrecognized
                    r(199);
                    
                    . 
                    . drop(_cons) nomtitles collab(none) starlevels( * 0.10 ** 0.05 *** 0.010) replace ///
                    variable _cons not found
                    r(111);
                    
                    . 
                    . addnotes("Some description of the dependent variables and models HERE." ///
                    command addnotes is unrecognized
                    r(199);
                    
                    . 
                    . "Wild cluster t-statistics and p-values in parentheses and brackets, respectively." "* p<0.10, ** p<0.05, *** p<0.01") ///
                    "Wild cluster t-statistics and p-values in parentheses and brackets, respectively. is not a valid command name
                    r(199);
                    
                    . 
                    . varwidth(30) stats(N r2_a, labels(Observations "Adjusted R-squared") fmt(a3))
                    command varwidth is unrecognized
                    r(199);
                    Same as above, even if I delete the ///, it still gets stuck.

                    Sorry for the lengthy and rambling reply. Thank You for your help!

                    Comment


                    • #11
                      You need to run the code in a do-file. The command line is too long, so I split it over several lines to make it readable. "///" represents a line-break.
                      Last edited by Andrew Musau; 20 Feb 2022, 12:35.

                      Comment


                      • #12
                        Thanks heaps! Got it! Thank you for the help (and for being sooo patient)!

                        By the way, the constant should be the same as before, right?

                        Have a fruitful and happy new week!

                        Comment


                        • #13
                          Originally posted by Vania Stef View Post

                          By the way, the constant should be the same as before, right?
                          You will usually not report the constant in fixed effects models as it is collinear with the fixed effects and thus its coefficient is meaningless. To illustrate this, note that the coefficient on the constant changes once I change the base category on the company indicators in the Grunfeld dataset.

                          Code:
                          webuse grunfeld, clear
                          regress invest mvalue ib2.company
                          regress invest mvalue ib7.company
                          Res.:

                          Code:
                          . regress invest mvalue ib2.company
                          
                                Source |       SS           df       MS      Number of obs   =       200
                          -------------+----------------------------------   F(10, 189)      =    106.36
                                 Model |   7947627.4        10   794762.74   Prob > F        =    0.0000
                              Residual |  1412316.51       189  7472.57415   R-squared       =    0.8491
                          -------------+----------------------------------   Adj R-squared   =    0.8411
                                 Total |  9359943.92       199  47034.8941   Root MSE        =    86.444
                          
                          ------------------------------------------------------------------------------
                                invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                          -------------+----------------------------------------------------------------
                                mvalue |   .1898776   .0179944    10.55   0.000     .1543819    .2253733
                                       |
                               company |
                                    1  |  -250.9496   50.53491    -4.97   0.000    -350.6345   -151.2647
                                    3  |  -302.3937   27.34152   -11.06   0.000    -356.3275     -248.46
                                    4  |  -81.57121   35.72985    -2.28   0.024    -152.0517   -11.09068
                                    5  |  -18.21815   41.56912    -0.44   0.662    -100.2172    63.78089
                                    6  |  -60.38163   39.07881    -1.55   0.124    -137.4683    16.70504
                                    7  |  -16.91595   42.68734    -0.40   0.692    -101.1208    67.28889
                                    8  |  -120.5689   35.98956    -3.35   0.001    -191.5618   -49.57611
                                    9  |  -57.53333   40.20212    -1.43   0.154    -136.8358    21.76916
                                   10  |  -46.45149   43.78681    -1.06   0.290    -132.8251    39.92215
                                       |
                                 _cons |   36.06969   40.40532     0.89   0.373    -43.63364     115.773
                          ------------------------------------------------------------------------------
                          
                          .
                          . regress invest mvalue ib7.company
                          
                                Source |       SS           df       MS      Number of obs   =       200
                          -------------+----------------------------------   F(10, 189)      =    106.36
                                 Model |   7947627.4        10   794762.74   Prob > F        =    0.0000
                              Residual |  1412316.51       189  7472.57415   R-squared       =    0.8491
                          -------------+----------------------------------   Adj R-squared   =    0.8411
                                 Total |  9359943.92       199  47034.8941   Root MSE        =    86.444
                          
                          ------------------------------------------------------------------------------
                                invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                          -------------+----------------------------------------------------------------
                                mvalue |   .1898776   .0179944    10.55   0.000     .1543819    .2253733
                                       |
                               company |
                                    1  |  -234.0336    80.0986    -2.92   0.004    -392.0357   -76.03153
                                    2  |   16.91595   42.68734     0.40   0.692    -67.28889    101.1208
                                    3  |  -285.4778   42.26727    -6.75   0.000     -368.854   -202.1016
                                    4  |  -64.65526   29.03234    -2.23   0.027    -121.9243   -7.386202
                                    5  |  -1.302198   27.37549    -0.05   0.962    -55.30296    52.69857
                                    6  |  -43.46568   27.76464    -1.57   0.119    -98.23408    11.30272
                                    8  |   -103.653   28.89966    -3.59   0.000    -160.6603   -46.64567
                                    9  |  -40.61739   27.53549    -1.48   0.142    -94.93376    13.69899
                                   10  |  -29.53555   27.37282    -1.08   0.282    -83.53105    24.45995
                                       |
                                 _cons |   19.15374    19.5165     0.98   0.328    -19.34441    57.65189
                          ------------------------------------------------------------------------------
                          
                          .

                          Comment


                          • #14
                            Vania:
                            as an aside to Andrew's helpful reply, you may want to take a look at: https://stats.oarc.ucla.edu/stata/fa...d-by-xtreg-fe/
                            Kind regards,
                            Carlo
                            (StataNow 18.5)

                            Comment


                            • #15
                              Thank You both for the invaluable help! Much appreciated!

                              Comment

                              Working...
                              X