Announcement

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

  • coefplot: group results by DV and label by coefficient

    Hello,
    Take the following example data

    Code:
    * create base data
    sysuse auto,clear
    gen brand = word(make, 1)
    keep if inlist(brand, "Audi", "Fiat", "Olds", "Pont.")
    encode brand, generate(brand_en)
    
    * estimate regression of interest
    reg price ibn.brand_en,nocons
    eststo rpr
    reg weight ibn.brand_en,nocons
    eststo rwe
    reg length ibn.brand_en,nocons
    eststo lwe
    I am estimating the effect of brands on price, weight and length.
    I am using coefplot to present my results

    Code:
    coefplot (rpr,label(Price) pstyle(p3) msymbol(Oh) offset(-0.25)) (rwe,label(weight)  msymbol(S) pstyle(p2)) (lwe,label(Length)  msymbol(D) pstyle(p4) offset(0.25)), vert  ciopts(lwidth(medium) recast(rcap)) ylabel(,grid) plotregion(margin(vlarge))  //
    This is the resulting plot:
    Click image for larger version

Name:	Screenshot 2023-09-12 at 12.30.39.png
Views:	3
Size:	42.0 KB
ID:	1726866

    To ease interpretation, I would like to change this plot. The x axis should consist of the three dependent variables, hence the coefficients for the same DV should be close to one another. Different colors should be used in each coefficient bar, to indicate the brands (Audi, Fiat, Ods, etc..). In other words, I would like to swap the regressor in the x-axis, with the DVs in the legend box.

    I am not sure how to do this: does anyone knows how I could do this, with coefplot or in other ways?

    thanks a lot in advance for your help

    Attached Files

  • #2
    coefplot is from SSC, as you are asked to explain (FAQ Advice #12). suest is one way to combine estimates from regress. See

    Code:
    help suest
    Code:
    * create base data
    sysuse auto,clear
    gen brand = word(make, 1)
    keep if inlist(brand, "Audi", "Fiat", "Olds", "Pont.")
    encode brand, generate(brand_en)
    
    * estimate regression of interest
    reg price ibn.brand_en,nocons
    eststo rpr
    reg weight ibn.brand_en,nocons
    eststo rwe
    reg length ibn.brand_en,nocons
    eststo lwe
    
    suest rpr rwe lwe
    est sto all
    set scheme s1color
    coefplot (all, keep(*:1.brand_en)) (all, keep(*:2.brand_en)) ///
    (all, keep(*:3.brand_en)) (all, keep(*:4.brand_en)), ///
    eqlabels(Price Weight Length) vert nokey
    Res.:

    Click image for larger version

Name:	Graph.png
Views:	1
Size:	30.7 KB
ID:	1726955

    Comment


    • #3
      Thank you Andrew,
      This is really helpful!

      I was wondering, however, if there is a way to use suest using bootstrap standard errors.

      In the actual data, I am running these regressions,

      Code:
      * estimate regression of interest
      reg price ibn.brand_en,nocons vce(bootstrap, rep(99))
      eststo rpr
      reg weight ibn.brand_en,nocons vce(bootstrap, rep(99))
      eststo rwe
      reg length ibn.brand_en,nocons vce(bootstrap, rep(99))
      eststo lwe
      suest rpr rwe lwe
      and if i run suest I get an error:
      Code:
      suest rpr rwe lwe
      rpr was estimated with a nonstandard vce (bootstrap)
      Is there a way to use suest for boostrap standard errors? otherwise are there other ways of obtaining this plot? perhaps using combomarginsplot? thanks a lot

      Comment


      • #4
        Code:
        bootstrap, reps(99): mvreg price weight length= ibn.brand_en, nocons
        See

        Code:
        help mvreg

        Comment


        • #5
          thanks!

          Comment


          • #6
            Dear Andrew, one quick question, it appears that I get slightly different results if I do
            Code:
            bootstrap, reps(99): mvreg price weight length= ibn.brand_en, nocons or
            bootstrap, reps(99): mvreg price = ibn.brand_en, nocons
            Note that the results in this latter case are equivalent to running
            Code:
            reg price ibn.brand_en,nocons vce(bootstrap, rep(99) seed(123))
            How is this possible? what can I do if I want to keep baseline estimation?

            Comment


            • #7
              There is a random element inherent in the bootstrapping procedure. In each iteration of the bootstrap process, a sample is drawn from the original dataset by randomly selecting data points with replacement. This means that some data points may be included multiple times in a bootstrap sample, while others may not be included at all. You repeat the resampling process many times (indicated by -reps()-) to generate a distribution of the statistic of interest. That is why you set the seed if you want to reproduce the same results. See

              Code:
              help bootstrap


              Code:
              bootstrap, reps(99) seed(123): mvreg price weight length= ibn.brand_en, nocons or
              bootstrap, reps(99) seed(123): mvreg price = ibn.brand_en, nocons

              Comment


              • #8
                So my issue does not appear to be with SEs, but rather with point estimates. Unfortunately I can't do this with the example data, but I will show you my results with real data.

                Say I want to estimate this model

                Code:
                reg y1 ib4.x, cluster(factory_code) vce(bootstrap, rep(99) seed(123))
                I get the following results

                Code:
                                                  (Replications based on 50 clusters in factory_code)
                --------------------------------------------------------------------------------------
                                     |   Observed   Bootstrap                         Normal-based
                              y1 | coefficient  std. err.      z    P>|z|     [95% conf. interval]
                ---------------------+----------------------------------------------------------------
                      biq_combined_c |
                    x1  |   .0562682    .079509     0.71   0.479    -.0995665    .2121029
                    x2 |   .2881812   .0613841     4.69   0.000     .1678705    .4084918
                      x3  |   .3174499   .0634304     5.00   0.000     .1931286    .4417711
                x5  |    .133072   .0721366     1.84   0.065    -.0083131    .2744572
                                     |
                               _cons |  -.1583722   .0584802    -2.71   0.007    -.2729913    -.043753
                --------------------------------------------------------------------------------------
                Note that the coefficient on x2 is .288

                However if I estimate the same model as part of mvreg, I obtain a different coefficient

                Code:
                bootstrap, reps(99) seed(123) cluster(factory_code): mvreg y1 y2 y3 y4= ib4.x
                I get the following results
                Code:
                                                   (Replications based on 50 clusters in factory_code)
                --------------------------------------------------------------------------------------
                                     |   Observed   Bootstrap                         Normal-based
                                     | coefficient  std. err.      z    P>|z|     [95% conf. interval]
                ---------------------+----------------------------------------------------------------
                y1               |
                      biq_combined_c |
                    x1  |   .0528582    .085247     0.62   0.535    -.1142229    .2199393
                    x2  |   .2864781   .0589678     4.86   0.000     .1709033     .402053
                      x3  |   .3137325   .0643007     4.88   0.000     .1877056    .4397595
                x5  |   .1154333   .0741515     1.56   0.120     -.029901    .2607677
                                     |
                               _cons |  -.1518942   .0622998    -2.44   0.015    -.2739995   -.0297888
                As you can see results from mvreg are different. The coefficient on x2 is 2.86, rather than 2.88. Given that the reason to run mvreg, is to plot my results for the baseline equations, I would want them to be identical. Do you know why this is happening?
                Last edited by Tom Ford; 18 Sep 2023, 07:03.

                Comment

                Working...
                X