Announcement

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

  • Plot coefficients with bootstrapped confidence intervals for multiple dummies in one regression

    Dear Statalist,

    I am trying to make a graph of all 20 coefficients with the bootstrapped CIs of 20 (leader) dummies from the following regression:

    Code:
    forvalues i = 1/20 {
        gen leader`i' = (leaderID==`i')
    }
    
    reg Y leader* X1 X2 X3 X4, noconstant cluster(leaderID)
    I try to use
    Code:
    wildbootstrap reg Y leader* X1 X2 X3 X4, noconstant cluster(leaderID)
    coefplot, baselevels keep(leader*)
    But it does not show bootstrapped CIs. It shows CIs from the regression: reg Y leader* X1 X2 X3 X4, noconstant cluster(leaderID).

    I also try to use boottest following this post https://www.statalist.org/forums/for...ence-intervals, but I cannot find a way with boottest.
    Any help would be appreciated.
    Many thanks in advance.

  • #2
    Try:
    Code:
    wildbootstrap reg Y leader* X1 X2 X3 X4, noconstant cluster(leaderID) coef(leader*)
    matrix C = r(table)["b",.] \ r(table)["ll",.] \ r(table)["ul",.]
    coefplot matrix(C), ci((2 3)) baselevels

    Comment


    • #3
      Hi Kumar,

      Thanks for your suggestion.
      I try your codes, but I got an error C: invalid syntax in ci()

      I slightly change the coefplot code to
      Code:
      coefplot matrix(C), ci((ci_bc[2] ci_bc[3]))
      My code only show the coefficients. It does not show CIs.
      Could you advise on how to resolve this?

      Comment


      • #4
        Can you show me the exact code you are using, starting with your wildbootstrap command? I had tested the code in #2 on another dataset, so it should not have produced that error. Also, as suggested in the forum FAQ, it always helps when you provide a data example using the dataex command.

        Comment


        • #5
          Hi Kumar,

          I follow your previous suggestion and got the error C: invalid syntax in ci()
          Code:
          wildbootstrap reg Y leader* X1 X2 X3 X4, noconstant cluster(leaderID) coef(leader*)
          matrix C = r(table)["b",.] \ r(table)["ll",.] \ r(table)["ul",.]
          coefplot matrix(C), ci((2 3)) baselevels
          I then slightly change the codes regarding coefplot. The above error does not come out, but the graph does not show CIs.
          Code:
          wildbootstrap reg Y leader* X1 X2 X3 X4, noconstant cluster(leaderID) coef(leader*)
          matrix C = r(table)["b",.] \ r(table)["ll",.] \ r(table)["ul",.]
          coefplot matrix(C), ci((ci_bc[2] ci_bc[3]))
          I understand that providing a data sample would be helpful for addressing questions more effectively. However, due to usage regulations regarding the data I'm working with, I’m unable to share a sample. I am sorry for any inconvenience this may cause.

          Comment


          • #6
            As suggested in the FAQ, when your data is sensitive, one alternative is using datasets provided by Stata. Here is a reproducible version of my solution:

            Code:
            sysuse nlsw88, clear
            
            rename (wage industry age hours tenure collgrad) (Y leaderID X1 X2 X3 X4)
            
            forvalues i = 1/12 {
                gen leader`i' = (leaderID==`i')
            }
            
            wildbootstrap reg Y leader* X1 X2 X3 X4, noconstant cluster(leaderID) coef(leader*)
            matrix C = r(table)["b",.] \ r(table)["ll",.] \ r(table)["ul",.]
            
            coefplot matrix(C), ci((2 3)) baselevels
            Here the wildbootstrap output is:

            Code:
            Wild cluster bootstrap                             Number of obs      = 2,213
            Linear regression                                  Number of clusters =    12
                                                               Cluster size:
            Cluster variable: leaderID                                        min =     4
            Error weight: Rademacher                                          avg = 184.4
                                                                              max =   815
            -----------------------------------------------------------------------------
                                   Y |   Estimate      t  p-value    [95% conf. interval]
            -------------------------+---------------------------------------------------
            constraints              |
                        leaderID = 0 |   .6582282   11.80   0.004    .5566756    .8287446
                         leader1 = 0 |   4.587576    6.70   0.010    2.616149    8.090896
                         leader2 = 0 |   13.80054   26.32   0.006    8.756559    20.90045
                         leader3 = 0 |   5.420142   10.14   0.008    3.782845    7.585453
                         leader4 = 0 |   4.162726    9.55   0.000    3.329946    5.754276
                         leader5 = 0 |   7.045373   18.48   0.000    6.371985    8.461219
                         leader6 = 0 |    1.97545    5.09   0.014    1.087349    3.057915
                         leader7 = 0 |   4.618751   16.18   0.004    3.936329    6.051695
                         leader8 = 0 |   1.906992    6.68   0.028     .411966    2.728076
                         leader9 = 0 |  -1.050857   -3.77   0.230    -2.82707    1.166074
                        leader10 = 0 |  -.5883985   -2.87   0.380    -10.0006    9.534447
                        leader11 = 0 |  -.9660532   -9.52   0.242   -1.618082    2.561457
            -----------------------------------------------------------------------------
            and the corresponding coefplot graph is
            Click image for larger version

Name:	Screenshot 2025-04-27 at 10.44.05 AM.png
Views:	1
Size:	194.9 KB
ID:	1776608




            I am afraid I can't troubleshoot your code since I cannot replicate your problem. In your altered version of my code, I also don't know what ci_bc is.

            Edit: I did just notice one problem -- because of the way you use wildcards to specify leader dummies, you will end up including the original leaderID variable as well. To avoid this, you should use leader1-leader20 instead of leader* in the wildbootstrap command.
            Last edited by Hemanshu Kumar; 26 Apr 2025, 23:24.

            Comment


            • #7
              You may also want to check whether you have an old version of coefplot installed. Type
              Code:
              which coefplot
              to see the version. In my case it is
              Code:
              *! version 1.8.6  22feb2023  Ben Jann
              If you have an older version, you may want to run
              Code:
              adoupdate, update
              to update it and other community-contributed packages.

              Comment


              • #8
                Hi Kumar,
                You're a lifesaver!
                Your suggested codes worked perfectly after I update the coefplot package.
                Thank you so much for your help!

                Comment

                Working...
                X