Announcement

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

  • coefplot : groups() option not producing desired results

    Hi Stata users,
    I am using coefplot in Stata 15 to try and replicate the graph below where there are labels for different coefficients on the left.
    Click image for larger version

Name:	coefplot.png
Views:	1
Size:	186.1 KB
ID:	1561582

    The code runs successfully but the labels aren’t drawn.

    Example of data am using is below
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(gr1_v1 gr1_v3 gr1_v4) byte gr2_v1 double(gr2_v2 ctr3 ctr2 ctr5) int ctr4 byte gr1_v2 double(ctr1 dep)
    -.6599468 .899                . 0 31.1           58.319  3.266513294718 25.5  460  7 4.01296965034928  1.01532756627686
     .0217204 .729 75.0666666666667 0 40.7            72.95  2.654591643397 28.2  505  9 7.39194513263972  1.10688086439221
     1.208909 .128                . 0 60.3 81.1243902439025 4.0700396132298 50.5 1844  0 21.9561365414532  4.90884672095601
     1.002136 .025 21.0076857386849 0 65.9 83.3292682926829 4.1766247543894   83 2322  1 19.3798772302397  6.36412555386142
     .3499596 .719 53.8528896672504 0 73.2           76.683  2.537743924381   81  496  8 11.9009501051758  .599379329093928
     1.084034 .071 39.7115351934217 0 58.3           79.909 3.3414406424637 72.7 1171  3 11.5299351385754  3.93969045852249
     .3403786 .688 47.9964902018134 0 54.8           63.538  3.494744343401 81.5  576  8 5.31785410434149  2.44881843884806
     1.887119 .022                . 0 64.6  82.509756097561 4.5896387574232 58.6 5281  2 17.0491024330957  3.81613775512702
     .4873109 .192 16.6160081053698 0   54 76.0634146341464 2.7878603854949 55.5 1293  0 19.1578000000818  3.98688878065147
    -1.457285 .581                . 0 32.3            64.13  3.888609794346 44.8    8 20 2.58482735006572    2.030489676202
    -.5659866 .385                . 0 28.8           61.174  2.790786304386 24.2   17 10 3.25357804338301  .232070929491975
     1.480526 .052                . 0 68.2 82.5243902439024 4.3359284092312 75.3 3964  1 20.0350636225599   6.0631190563328
     -.568605 .919                . 0 39.2           69.289  3.093067878339 57.7   50 10 4.56857986788513                 0
     1.850466 .026 34.5835631549917 0 75.6 81.5609756097561 4.2323386934973   86 4252  0 19.1964320948507  5.84410294800882
    -.6115379 .829 57.9370395177495 0 49.3             71.2  1.890168286892 64.7   94 12 4.49463845131904  1.26144642965273
    -.6234712 .449                . 0 34.2            61.44  1.818830837499 36.9   14 15 2.58992799444937  .363654340665717
     .6626508 .138 17.6724137931034 0 55.4 77.8512195121951 2.8154505203677 61.7 1244  0 17.5172687114464  3.35607047107291
     .3234982 .632                . 1 49.3           74.874  3.468560666431 74.4 2114  8 3.31359274838029   2.6803724019718
     .4569183 .401                . 0 53.3 77.8268292682927 2.7646862730083 72.3 1334  2 20.4465533534434   3.2656320131974
     -2.19103 .808                . 0 16.6           56.709  3.400798436406 21.5    . 20 2.87330473821098  1.75740818499543
    -1.554787 .766                . 0 26.5           60.026  3.852251229028 25.1    4 24 3.01784062159803  .599255783985903
    -1.068652 .425                . 0 43.4           66.558   3.22893746746 59.2   58 18 5.78468598810298  .105903309510554
    -.7286705 .643                . 0   28           63.279  3.803750090162 23.3   32 13 2.64539308279661  .199233471764191
    -.8742813 .707                . 0 28.1           59.309  2.787749626316 29.3   33 11 2.89079230574002 .0656059745175615
    -1.097704 .887                . 0 32.3           70.647  1.605546963219 24.1   60 11  3.0218758999859  1.81878434488838
     1.043452 .143                . 0 62.9 74.6804878048781  3.062378374171 97.3  868  0 20.0437012952645    2.599236926728
    -.8024699  .76 20.9441464050046 0 43.1           74.068 3.1349399700806 39.9  297  7 5.24747224234179  1.85837971028276
     1.596495 .041  31.767955801105 0 75.5 82.4975609756098 3.8827269902903 97.3 3094  2 15.6567740028615  1.62586765721305
     .8301269    .                . 0    .                .               .    .    .  .                .                 .
    -.4302173 .693                . 0 37.7           76.271  3.577294022314 37.7  853  9 6.18465081086714  4.55230246460259
    -.6820061 .737 16.2442103529089 0 32.7            73.81   3.28682451749   50  172  8 4.81210741748212   1.8274571050858
    -.2092959 .648 47.6702508960573 0 43.7           76.218   3.77476883394 56.8  218  7 7.01285998016383  1.88806509478269
     .6312364 .533 83.5707502374169 0 41.2           79.981  3.408640114945 32.7 3205  3 1.36989305372263  2.63489390958162
    -.4152199 .463 24.8666666666667 0   38 71.7809756097561  3.265953556417 36.5  227  9  16.434413962673  2.80925249570885
     .2830485 .402 50.3917860037828 0 46.5           69.165  3.018352798177 47.4   61 11 6.17995757333666  1.54224992948802
      .112718 .471 55.5555555555556 0 42.1           74.292  2.697290824098 42.9  313  7 3.84666107741343  .643944595030249
     1.125806 .115 7.98076923076923 0 67.2 81.1756097560976 2.7736630289271 73.7 2004  0 19.6069808775183  3.97172390436354
    -1.022591 .811 36.2706083001706 0 37.8            53.95  2.097026014282 44.6   28 18 2.74737722689511  .846933888122284
    -.7266325 .757                . 0 27.5           64.464  2.843522294086 39.5   60 16 3.14108516780183  1.71236057288775
     1.182665 .079  49.874686716792 1 70.2 82.6268292682927 3.6666145367932 92.1 1604  0 14.4185012031302  1.82656471855618
     1.716108 .034                . 1 75.3 82.2489756097561 4.2290833128677 96.4 3465  0 17.2323560257884   5.2434788559126
    -.4002573  .96 22.2787385554425 0 38.3           73.689  3.039886524686 37.1  428  3 7.08287675970026  3.84844519339733
     1.675817  .03 27.4238227146814 0 59.8  84.099756097561 3.7491687516534 70.1 3839  1 27.5771763175428   2.0797342180702
    -.7562658 .172                . 0 36.4           64.479  3.701542401593   42   45 10 2.60131742500686  .316910909325943
     .1902379 .141 36.6982124079916 0 36.6           73.245 3.2898275146162 14.7 1151  3 10.7346218102857  1.91042858698441
    -.9023383 .675                . 0 35.1           70.169  3.230997207665   22   29  9 5.72755051459756  .193603785720567
    -.4439246 .627 38.7619047619048 0 23.6           76.499  3.589836161482   12  676 11 6.36249574901306  2.77933499954802
    -.5172144 .613 27.2790265899743 0 35.7           73.992 3.3022770624888 34.6  396  8 6.43021038744429  .948313471566443
     1.871631 .016                . 0 70.4 81.0048780487805 4.2207698434522   86 4284  0  19.812929220959  4.59550973875025
    end
    The code is below
    Code:
        use "data.dta", clear
        
        global controls ctr1 ctr2 ctr3 ctr4 ctr5 
    
        foreach var in gr1_v1 gr1_v2 gr1_v3 gr1_v4 {
            preserve
            center dep `var', inplace standardize
            regress dep `var', noconstant
            estimates store g1_b_`var'
            restore
        }
    
        foreach var in gr1_v1 gr1_v2 gr1_v3 gr1_v4 {
            preserve
            center dep `var' $controls, inplace standardize
            regress dep `var' $controls, noconstant
            estimates store g1_c_`var'
            restore
        }
    
        
        foreach var in gr2_v1 gr2_v2 {
            preserve
            center dep `var', inplace standardize
            regress dep `var', noconstant
            estimates store g2_b_`var'
            restore
        }
    
        foreach var in gr2_v1 gr2_v2 {
            preserve
            center dep `var' $controls, inplace standardize
            regress dep `var' $controls, noconstant
            estimates store g2_c_`var'
            restore
        }
    
    
        coefplot (*_b_*, label(Bivariate) pstyle(p3)) (*_c_*, label(With Controls) pstyle(p4)), ///
            bylabel(Price) msymbol(S) drop(_cons $controls) xline(0) coeflabels(, labsize(vsmall)) ///
            legend( size(vsmall)) ///
            groups(g1_b_? g1_c_? = "Group 1" g2_b_? g2_c_? = "Group 4")
    Thanks in advance!

  • #2
    g1_b_?, g1_c_?, g2_b_?, and g2_c_? do not refer to any coefficients in the model. Maybe this is what you want:

    Code:
    coefplot (*_b_*, label(Bivariate) pstyle(p3)) (*_c_*, label(With Controls) pstyle(p4)), ///
        bylabel(Price) msymbol(S) drop(_cons $controls) xline(0) coeflabels(, labsize(vsmall)) ///
        legend( size(vsmall)) ///
        groups(gr1_* = "Group 1" gr2_* = "Group 4")

    Comment


    • #3
      Thanks so much Ben Jann !! This is really what I want. I sincerely appreciate the help.

      Comment

      Working...
      X