Announcement

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

  • Margins at min, max and median values of variable (after xtreg)

    Dear Statalisters,

    I am running a Panel Data Analysis ((Hausman test) Fixed and Random Effects regression model with a command xtreg including an interaction between two variable that varies within panels - i.e. Ownership_concentration and Lerner index. My panel data is split by banks,countries and years. The variable ownership_concentration has a value for each bank, where the variable Lerner has a value for each country.

    I want to obtain the min, max and median using the margins command and evaluate the effect of ownership concentration on bank performance (ratio called EARTA) at the minimum, median and maximum levels of the Lerner index . However, I seem to either miss something in the syntax or STATA is not be unable to estimate what I want. Here is an illustrating example:

    Code:
    . xtreg earta ownership_concentration lerner ownconlerner ownconccovid19 lernercovid19 cir nldepstfunding size luqidasset equitytotalassets llptotalloans gdp_growth inflation islamic_d covid19_dummy d_iraq d_bahrain d_syrianarabrepublic d_palestinianterritories d_oman d_tunisia d_yemen d_saudiarabia d_jordan d_kuwait d_iran d_unitedarabemirates d_qatar d_lebanon d_egypt d_morocco d_libya d_algeria d_israel d_malta, fe
    note: covid19_dummy omitted because of collinearity
    note: d_libya omitted because of collinearity
    note: d_malta omitted because of collinearity
    
    Fixed-effects (within) regression               Number of obs      =      2167
    Group variable: y                               Number of groups   =        16
    
    R-sq:  within  = 0.2803                         Obs per group: min =        44
           between = 0.4438                                        avg =     135.4
           overall = 0.2340                                        max =       194
    
                                                    F(32,2119)         =     25.79
    corr(u_i, Xb)  = -0.5324                        Prob > F           =    0.0000
    
    ------------------------------------------------------------------------------------------
                       earta |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------------------+----------------------------------------------------------------
     ownership_concentration |   .0059562   .0024705     2.41   0.016     .0011114    .0108009
                      lerner |   .0121662   .0049778     2.44   0.015     .0024043    .0219281
                ownconlerner |  -.0164077   .0058931    -2.78   0.005    -.0279645   -.0048509
              ownconccovid19 |  -.0026284    .002828    -0.93   0.353    -.0081743    .0029174
               lernercovid19 |  -.0015191   .0045828    -0.33   0.740    -.0105063     .007468
                         cir |   -.001471   .0017703    -0.83   0.406    -.0049427    .0020008
              nldepstfunding |   .0077461   .0014321     5.41   0.000     .0049376    .0105547
                        size |   .0017732   .0002883     6.15   0.000     .0012078    .0023387
                  luqidasset |   .0019798   .0017517     1.13   0.259    -.0014555     .005415
           equitytotalassets |   .0036689   .0014629     2.51   0.012     .0008001    .0065378
               llptotalloans |  -.0060658   .0030525    -1.99   0.047     -.012052   -.0000797
                  gdp_growth |  -.0059167   .0060532    -0.98   0.328    -.0177876    .0059542
                   inflation |   .0027875   .0038994     0.71   0.475    -.0048595    .0104345
                   islamic_d |   .0017168    .000785     2.19   0.029     .0001773    .0032564
               covid19_dummy |          0  (omitted)
                      d_iraq |   .0075815   .0034456     2.20   0.028     .0008244    .0143387
                   d_bahrain |   .0107113   .0035187     3.04   0.002     .0038108    .0176118
        d_syrianarabrepublic |   .0118167   .0035673     3.31   0.001     .0048209    .0188125
    d_palestinianterritories |   .0235419   .0039567     5.95   0.000     .0157824    .0313014
                      d_oman |   .0170214    .003953     4.31   0.000     .0092693    .0247736
                   d_tunisia |   .0157249   .0037031     4.25   0.000     .0084628    .0229869
                     d_yemen |   .0082683   .0051588     1.60   0.109    -.0018486    .0183851
               d_saudiarabia |   .0164683   .0039985     4.12   0.000     .0086269    .0243098
                    d_jordan |   .0235108   .0036057     6.52   0.000     .0164397    .0305818
                    d_kuwait |   .0112048   .0040661     2.76   0.006     .0032308    .0191789
                      d_iran |  -.0062299    .003572    -1.74   0.081     -.013235    .0007751
        d_unitedarabemirates |   .0174788   .0039005     4.48   0.000     .0098297     .025128
                     d_qatar |    .012014    .004056     2.96   0.003     .0040599    .0199681
                   d_lebanon |   .0123726   .0032784     3.77   0.000     .0059433    .0188019
                     d_egypt |    .026163   .0033168     7.89   0.000     .0196585    .0326676
                   d_morocco |   .0221602   .0036586     6.06   0.000     .0149854    .0293351
                     d_libya |          0  (omitted)
                   d_algeria |   .0227315   .0041034     5.54   0.000     .0146845    .0307785
                    d_israel |   .0120014   .0035523     3.38   0.001     .0050351    .0189677
                     d_malta |          0  (omitted)
                       _cons |  -.0161335   .0041132    -3.92   0.000    -.0241998   -.0080673
    -------------------------+----------------------------------------------------------------
                     sigma_u |  .00430835
                     sigma_e |  .01308236
                         rho |  .09784356   (fraction of variance due to u_i)
    ------------------------------------------------------------------------------------------
    F test that all u_i=0:     F(15, 2119) =     3.55            Prob > F = 0.0000
    I have manually computed the Min, Max and the Median of the marginal effect so firstly I tried to put them manually in stata as follows:

    Code:
    . margins ownership_concentration, at( ownconlerner=(0.0009 (-0.0044335964044118) -0.00740213039667478))
    ownership_concentration:  factor variables may not contain noninteger values
    r(452);
    And it didn't work. I also tried the following:

    Code:
    . margins , dydx( ownership_concentration ownconlerner)
    
    Average marginal effects                          Number of obs   =       2167
    Model VCE    : Conventional
    
    Expression   : Linear prediction, predict()
    dy/dx w.r.t. : ownership_concentration ownconlerner
    
    -----------------------------------------------------------------------------------------
                            |            Delta-method
                            |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
    ------------------------+----------------------------------------------------------------
    ownership_concentration |   .0059562   .0024705     2.41   0.016     .0011141    .0107982
               ownconlerner |  -.0164077   .0058931    -2.78   0.005    -.0279579   -.0048575
    -----------------------------------------------------------------------------------------
    
    . summarize ownership_concentration
    
        Variable |       Obs        Mean    Std. Dev.       Min        Max
    -------------+--------------------------------------------------------
    ownership~on |      2167    .4421175    .2853384   .0025035          1
    
    . 
    . local min = r(min)
    
    . 
    . local max = r(max)
    
    . 
    . local mean = r(mean)
    
    . margins ownconlerner, at ( ownership_concentration = (`min' `mean' `max'))
    ownconlerner:  factor variables may not contain noninteger values
    r(452);
    But again without any success. I read the posts for the factor variables, and the example provided by Carlo Lazzaro here - https://www.statalist.org/forums/for...integer-values , however I didn't quite get it how to apply this on my data and convert these variables in "factor variable" in order to run the margins command

    I will really appreciate if you can guide me how to run the margins at min, max and median values for my variables as this is the last bit of my paper.

    Thank you in advance for the help.

    Petko

  • #2
    Petko:
    you can get what you want, even stratified by country, using the functions -max-, -min- and -median- from -egen- and repeat the regression.
    However, if you're using an -fe- estimator, this approach will give you back no coefficient as those values will actually be time-invariant, as in the following toy-example:
    Code:
    . use "https://www.stata-press.com/data/r17/nlswork.dta"
    (National Longitudinal Survey of Young Women, 14-24 years old in 1968)
    
    
    . egen age_max=max(age)
    
    . egen age_min=min(age)
    
    . egen age_median=median(age)
    
    . list idcode year age age_max age_min age_median in 1/2
    
         +----------------------------------------------------+
         | idcode   year   age   age_max   age_min   age_me~n |
         |----------------------------------------------------|
      1. |      1     70    18        46        14         28 |
      2. |      1     71    19        46        14         28 |
         +----------------------------------------------------+
    
    . xtreg ln_wage c.age##c.age, fe vce(cluster idcode)
    
    Fixed-effects (within) regression               Number of obs     =     28,510
    Group variable: idcode                          Number of groups  =      4,710
    
    R-squared:                                      Obs per group:
         Within  = 0.1087                                         min =          1
         Between = 0.1006                                         avg =        6.1
         Overall = 0.0865                                         max =         15
    
                                                    F(2,4709)         =     507.42
    corr(u_i, Xb) = 0.0440                          Prob > F          =     0.0000
    
                                 (Std. err. adjusted for 4,710 clusters in idcode)
    ------------------------------------------------------------------------------
                 |               Robust
         ln_wage | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
             age |   .0539076    .004307    12.52   0.000     .0454638    .0623515
                 |
     c.age#c.age |  -.0005973    .000072    -8.30   0.000    -.0007384   -.0004562
                 |
           _cons |    .639913   .0624195    10.25   0.000     .5175415    .7622845
    -------------+----------------------------------------------------------------
         sigma_u |   .4039153
         sigma_e |  .30245467
             rho |  .64073314   (fraction of variance due to u_i)
    ------------------------------------------------------------------------------
    
    . xtreg ln_wage c.age_max##c.age_max , fe vce(cluster idcode)
    note: age_max omitted because of collinearity.
    note: c.age_max#c.age_max omitted because of collinearity.
    
    Fixed-effects (within) regression               Number of obs     =     28,534
    Group variable: idcode                          Number of groups  =      4,711
    
    R-squared:                                      Obs per group:
         Within  = 0.0000                                         min =          1
         Between = 0.0050                                         avg =        6.1
         Overall =      .                                         max =         15
    
                                                    F(0,4710)         =          .
    corr(u_i, Xb) =      .                          Prob > F          =          .
    
                                        (Std. err. adjusted for 4,711 clusters in idcode)
    -------------------------------------------------------------------------------------
                        |               Robust
                ln_wage | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
    --------------------+----------------------------------------------------------------
                age_max |          0  (omitted)
                        |
    c.age_max#c.age_max |          0  (omitted)
                        |
                  _cons |   1.674907          .        .       .            .           .
    --------------------+----------------------------------------------------------------
                sigma_u |  .42456905
                sigma_e |  .32028665
                    rho |  .63731204   (fraction of variance due to u_i)
    -------------------------------------------------------------------------------------
    
    . xtreg ln_wage c.age_min##c.age_min , fe vce(cluster idcode)
    note: age_min omitted because of collinearity.
    note: c.age_min#c.age_min omitted because of collinearity.
    
    Fixed-effects (within) regression               Number of obs     =     28,534
    Group variable: idcode                          Number of groups  =      4,711
    
    R-squared:                                      Obs per group:
         Within  = 0.0000                                         min =          1
         Between = 0.0050                                         avg =        6.1
         Overall =      .                                         max =         15
    
                                                    F(0,4710)         =          .
    corr(u_i, Xb) =      .                          Prob > F          =          .
    
                                        (Std. err. adjusted for 4,711 clusters in idcode)
    -------------------------------------------------------------------------------------
                        |               Robust
                ln_wage | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
    --------------------+----------------------------------------------------------------
                age_min |          0  (omitted)
                        |
    c.age_min#c.age_min |          0  (omitted)
                        |
                  _cons |   1.674907          .        .       .            .           .
    --------------------+----------------------------------------------------------------
                sigma_u |  .42456905
                sigma_e |  .32028665
                    rho |  .63731204   (fraction of variance due to u_i)
    -------------------------------------------------------------------------------------
    
    . xtreg ln_wage c.age_median##c.age_median , fe vce(cluster idcode)
    note: age_median omitted because of collinearity.
    note: c.age_median#c.age_median omitted because of collinearity.
    
    Fixed-effects (within) regression               Number of obs     =     28,534
    Group variable: idcode                          Number of groups  =      4,711
    
    R-squared:                                      Obs per group:
         Within  = 0.0000                                         min =          1
         Between = 0.0050                                         avg =        6.1
         Overall =      .                                         max =         15
    
                                                    F(0,4710)         =          .
    corr(u_i, Xb) =      .                          Prob > F          =          .
    
                                              (Std. err. adjusted for 4,711 clusters in idcode)
    -------------------------------------------------------------------------------------------
                              |               Robust
                      ln_wage | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
    --------------------------+----------------------------------------------------------------
                   age_median |          0  (omitted)
                              |
    c.age_median#c.age_median |          0  (omitted)
                              |
                        _cons |   1.674907          .        .       .            .           .
    --------------------------+----------------------------------------------------------------
                      sigma_u |  .42456905
                      sigma_e |  .32028665
                          rho |  .63731204   (fraction of variance due to u_i)
    -------------------------------------------------------------------------------------------
    
    .
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Dear Carlo,

      Thanks you very much for the clarification.

      I pretty much replicated what you have pointed out in your post.

      Code:
      . egen marginaleffect_max=max( marginaleffect)
      
      . egen marginaleffect_min=min( marginaleffect)
      
      . egen marginaleffect_median=median( marginaleffect)
      Code:
      . list banks1 y marginaleffect marginaleffect_max marginaleffect_min marginaleffect_median in 1/2
      
           +----------------------------------------------------------------------------------------+
           |                              banks1      y   margin~t   margin~x   margi~in   margi~an |
           |----------------------------------------------------------------------------------------|
        1. | A'AYAN LEASING & INVESTMENT COMPANY   2006    .007706   .9838272    -.08417   .0506804 |
        2. |           ABU DHABI COMMERCIAL BANK   2006   .1271085   .9838272    -.08417   .0506804 |
           +----------------------------------------------------------------------------------------+
      Indeed, however, as you mentioned in your post I did get no coefficient with -fe- estimator, example below:

      Code:
      . xtreg earta c.marginaleffect_max##c.marginaleffect_max, fe vce(cluster banks1)
      note: marginaleffect_max omitted because of collinearity
      note: c.marginaleffect_max#c.marginaleffect_max omitted because of collinearity
      
      Fixed-effects (within) regression               Number of obs      =      2167
      Group variable: banks1                          Number of groups   =       255
      
      R-sq:  within  = 0.0000                         Obs per group: min =         1
             between = 0.0000                                        avg =       8.5
             overall =      .                                        max =        16
      
                                                      F(0,254)           =         .
      corr(u_i, Xb)  =      .                         Prob > F           =         .
      
                                                                  (Std. Err. adjusted for 255 clusters in banks1)
      -----------------------------------------------------------------------------------------------------------
                                                |               Robust
                                          earta |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      ------------------------------------------+----------------------------------------------------------------
                             marginaleffect_max |          0  (omitted)
                                                |
      c.marginaleffect_max#c.marginaleffect_max |          0  (omitted)
                                                |
                                          _cons |   .0234518   8.95e-20  2.6e+17   0.000     .0234518    .0234518
      ------------------------------------------+----------------------------------------------------------------
                                        sigma_u |  .01310044
                                        sigma_e |  .01004804
                                            rho |  .62960814   (fraction of variance due to u_i)
      -----------------------------------------------------------------------------------------------------------
      I also tried using the random effect (-re- estimator) but I got the same results:

      Code:
      . xtreg earta c.marginaleffect_max##c.marginaleffect_max, re vce(cluster y)
      note: marginaleffect_max omitted because of collinearity
      note: c.marginaleffect_max#c.marginaleffect_max omitted because of collinearity
      
      Random-effects GLS regression                   Number of obs      =      2167
      Group variable: y                               Number of groups   =        16
      
      R-sq:  within  = 0.0000                         Obs per group: min =        44
             between = 0.0000                                        avg =     135.4
             overall = 0.0000                                        max =       194
      
                                                      Wald chi2(0)       =         .
      corr(u_i, X)   = 0 (assumed)                    Prob > chi2        =         .
      
                                                                        (Std. Err. adjusted for 16 clusters in y)
      -----------------------------------------------------------------------------------------------------------
                                                |               Robust
                                          earta |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
      ------------------------------------------+----------------------------------------------------------------
                             marginaleffect_max |          0  (omitted)
                                                |
      c.marginaleffect_max#c.marginaleffect_max |          0  (omitted)
                                                |
                                          _cons |   .0235835   .0005499    42.89   0.000     .0225057    .0246612
      ------------------------------------------+----------------------------------------------------------------
                                        sigma_u |  .00137272
                                        sigma_e |  .01530607
                                            rho |  .00797911   (fraction of variance due to u_i)
      -----------------------------------------------------------------------------------------------------------
      Can you please tell me what type of test should I use in order to test for the significance and get coefficients? Should I use the simple OLS regression?

      Thanks in advance for the help!

      Petko Bachvarov

      Comment


      • #4
        Petko:
        unfortunately, the only fix seems to think about a different specifucation of your regression model.
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          Hello Carlo,

          Thanks for the feedback.

          By specification, do you mean to change the model itself or not to use margins (test) at all?

          Thanks
          Petko

          Comment


          • #6
            Petko:
            I meant to change the right-hand side of your regressin equation.
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment

            Working...
            X