Announcement

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

  • Plotting coefficients using marginsplot

    Hello Statalist users,

    I run the following code to produce this figure:

    Code:
        eststo: reghdfe Man2Auto l.sharpe_ratio l.PercentAutoBid l.c.PercentAutoBid#l.c.PercentAutoBid ///
            l.inter2 l.inter3, a(LenderId hour LoanId) cluster(interaction)
                estadd local LenderId "Yes", replace
                estadd local hour "Yes", replace
                estadd local LoanId "Yes", replace
        est store AutoSwitching
        
            nlcom -_b[l.PercentAutoBid]/(2*_b[l.c.PercentAutoBid#l.c.PercentAutoBid])
        margins, at(l.PercentAutoBid = (0(0.1)1))
        marginsplot, /*
        */ plot1opts(lc(black) lp(longdash_dot)) ciopt(color(black)) plotopts(mcolor("black")) /*
        */ xline(.786, lstyle(grid) lp(longdash_dot) lc(maroon)) xti("Lag (Share Auto Bidding)") /*
        */ text(0.04 0.77 "Turning Point at 0.786", place(s) orient(vertical) color(black) size(small)) /*
        */ yti("Pr(Switch to Automatic = 1)") title("Panel B: Switching to Automatic") /*
        */ name(plot1, replace) nodraw


    If I want to add the coefficients of sharpe_ratio at different Share Auto Bidding Levels, is that possible using the marginsplot command? For example, If I want to put the coefficient of sharpe_ratio when Share Auto Bidding is 0, then at level 0.1 then at 0.2 and so on.

    Thank you for your time
    Attached Files

  • #2
    marginsplot has the -addplot()- option, which is essentially an embedded twoway command.

    addplot(plot) add other plots to the graph

    Comment


    • #3
      Hello again,

      I have tried adding addplot but it did not work. I am afraid that I can not share the dataset.

      Can anyone else help me with this? I just want to add the coefficients of sharpe at different Share Auto Bidding levels.

      This is the code that I have tried

      Code:
          loc sharpe_scale "0 (0.1) 1"
          marginsplot, /*
          */ plot1opts(lc(black) lp(longdash_dot)) ciopt(color(black)) plotopts(mcolor("black")) /*
          */ xline(.786, lstyle(grid) lp(longdash_dot) lc(maroon)) xti("Lag (Share Auto Bidding)") /*
          */ text(0.04 0.77 "Turning Point at 0.786", place(s) orient(vertical) color(black) size(small)) /* 
          */ yti("Pr(Switch to Automatic = 1)") title("Panel B: Switching to Automatic, Predictive Margins") /*
          */ addplot(hist sharpe_ratio, xlab(`sharpe_scale')) /*
          */ name(plot1, replace)
      Thank you for your time

      Comment


      • #4
        This is a small sample of the data but I do not know if it can work when running the regression:

        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input float(Man2Auto sharpe_ratio PercentAutoBid inter2 inter3) long LenderId float hour long LoanId float(bid_no interaction)
        0         . 0 . . 5  3 36049   1 180245
        0 .21666667 0 0 0 5  3 35964   2 179820
        0 .21666667 0 0 0 5  5 39221   3 196105
        0 .25301206 0 0 0 5 10 43513   4 217565
        1  .3333333 0 0 0 5 11 43513   5 217565
        0 .32977375 0 0 0 5  5 43575   6 217875
        0  .3244389 0 0 0 5  8 46201   7 231005
        0  .3415528 0 0 0 5  3 46721   8 233605
        0  .3401866 0 0 0 5  3 46748   9 233740
        0    .33733 0 0 0 5  1 49768  10 248840
        1  .3282166 0 0 0 5  3 50224  11 251120
        0 .32228765 0 0 0 5  1 50655  12 253275
        0 .16454336 0 0 0 5 10 51828  13 259140
        0  .1602107 0 0 0 5  3 51907  14 259535
        0  .1528938 0 0 0 5  5 51938  15 259690
        0 .15138413 0 0 0 5  9 51987  16 259935
        1 .14891744 0 0 0 5  2 52256  17 261280
        0 .14627574 0 0 0 5 10 52371  18 261855
        0 .14627574 0 0 0 5 11 52397  19 261985
        0 .14627574 0 0 0 5 11 52399  20 261995
        0 .14388342 0 0 0 5  2 52474  21 262370
        0 .14053027 0 0 0 5  2 53509  22 267545
        1 .14093415 0 0 0 5  3 53488  23 267440
        0 .14102887 0 0 0 5  4 53519  24 267595
        0 .14107072 0 0 0 5  2 54470  25 272350
        0 .14088441 0 0 0 5  6 55047  26 275235
        0 .14088441 0 0 0 5  9 56127  27 280635
        0 .13990068 0 0 0 5  6 56488  28 282440
        1 .13785581 0 0 0 5  7 57525  29 287625
        0 .13708752 0 0 0 5 12 57560  30 287800
        0 .13708752 0 0 0 5 10 58974  31 294870
        0 .13708752 0 0 0 5 10 58974  32 294870
        0 .13708752 0 0 0 5 10 58974  33 294870
        1 .13647835 0 0 0 5  2 59648  34 298240
        0 .13605163 0 0 0 5  7 60234  35 301170
        0 .13582873 0 0 0 5  8 60242  36 301210
        0 .13582873 0 0 0 5  8 60242  37 301210
        0 .13582873 0 0 0 5  8 60242  38 301210
        0 .13582873 0 0 0 5  8 60242  39 301210
        0 .13582873 0 0 0 5  8 60242  40 301210
        0 .13598594 0 0 0 5  3 60252  41 301260
        0 .13614044 0 0 0 5  6 60330  42 301650
        0 .13600872 0 0 0 5  6 60347  43 301735
        0 .13600872 0 0 0 5  8 60367  44 301835
        0 .13600872 0 0 0 5  8 60370  45 301850
        1 .13600872 0 0 0 5  8 60370  46 301850
        0 .13600872 0 0 0 5  8 60370  47 301850
        0 .13600872 0 0 0 5  8 60370  48 301850
        0 .13600872 0 0 0 5  8 60370  49 301850
        0 .13600872 0 0 0 5  8 60370  50 301850
        0 .13600872 0 0 0 5  8 60370  51 301850
        0 .13422458 0 0 0 5  9 60383  52 301915
        0 .13422458 0 0 0 5  9 60383  53 301915
        0 .13422458 0 0 0 5  9 60383  54 301915
        0 .13413852 0 0 0 5  9 60383  55 301915
        1 .13413852 0 0 0 5  9 60383  56 301915
        0 .13413852 0 0 0 5  9 60383  57 301915
        0   .134263 0 0 0 5 10 60385  58 301925
        0   .134263 0 0 0 5 10 60385  59 301925
        0   .134263 0 0 0 5 10 60385  60 301925
        0   .134263 0 0 0 5  2 60424  61 302120
        0 .13467865 0 0 0 5  6 60450  62 302250
        0 .13436422 0 0 0 5  7 60475  63 302375
        0 .13436422 0 0 0 5  7 60475  64 302375
        0 .13320361 0 0 0 5  8 60479  65 302395
        1 .13320361 0 0 0 5  8 60479  66 302395
        0 .13320361 0 0 0 5  8 60479  67 302395
        0 .13208786 0 0 0 5  8 60479  68 302395
        0 .13208786 0 0 0 5  8 60479  69 302395
        0 .13208786 0 0 0 5  8 60479  70 302395
        0 .13230121 0 0 0 5  2 60568  71 302840
        0 .13230121 0 0 0 5  9 60661  72 303305
        0 .13230121 0 0 0 5  3 60952  73 304760
        0  .1315668 0 0 0 5  9 61341  74 306705
        0  .1311615 0 0 0 5 15 61377  75 306885
        0  .1311615 0 0 0 5 15 61377  76 306885
        0  .1311615 0 0 0 5  5 61888  77 309440
        0 .13099633 0 0 0 5  8 60825  78 304125
        0 .13105783 0 0 0 5  8 62427  79 312135
        0 .13105783 0 0 0 5  3 63847  80 319235
        0 .12999278 0 0 0 5  7 64149  81 320745
        1 .12896506 0 0 0 5  7 63839  82 319195
        0 .12896506 0 0 0 5  7 63839  83 319195
        0 .12798658 0 0 0 5 10 63435  84 317175
        0 .12798658 0 0 0 5 10 63435  85 317175
        0 .12798658 0 0 0 5 10 63435  86 317175
        0 .12851042 0 0 0 5  4 64459  87 322295
        1 .12851042 0 0 0 5  6 64829  88 324145
        0 .12851042 0 0 0 5  6 64829  89 324145
        0 .12851042 0 0 0 5  6 64829  90 324145
        0 .12851042 0 0 0 5  8 65136  91 325680
        0 .12851042 0 0 0 5  8 65138  92 325690
        0 .12909941 0 0 0 5  4 65277  93 326385
        0  .1296838 0 0 0 5  4 65277  94 326385
        0  .1296838 0 0 0 5  4 65277  95 326385
        0  .1296838 0 0 0 5  4 65503  96 327515
        1 .12949708 0 0 0 5  7 63112  97 315560
        0 .12949708 0 0 0 5  7 63112  98 315560
        0 .12949708 0 0 0 5  3 66015  99 330075
        1 .12948221 0 0 0 5 11 66190 100 330950
        end

        Comment


        • #5
          Originally posted by Said Kaawach View Post
          This is a small sample of the data but I do not know if it can work when running the regression:
          You can and should test it before posting. Use the -count()- option of dataex if you have to present more observations and make sure that the code in #1 runs. As you are using time-series operators, also include the xtset command.

          Comment


          • #6
            Thank you Andrew,

            It seems that using dataex is not helpful, I will share a link where you can use the dataset and run the commands I previously posted if possible. It is panel data (xtset LenderId bid_no). These variables are included in the subsample here

            Best

            Said

            Comment


            • #7
              Not sure what you want to plot as there are several values of sharpe ratio over the range of lagged percent auto bid. Here is a graph of a linear regression line over these points presented alongside the margins results.

              Code:
              use "trial.dta", clear 
              xtset LenderId bid_no
              cap gen lp=l.PercentAutoBid
              bys lp: egen meansharpe= mean(sharpe_ratio)
              bys lp: g tag=_n==1
              sort LenderId bid_no
              eststo: reghdfe Man2Auto l.sharpe_ratio l.PercentAutoBid l.c.PercentAutoBid#l.c.PercentAutoBid ///
                      l.inter2 l.inter3, a(LenderId hour LoanId) cluster(interaction)
                          estadd local LenderId "Yes", replace
                          estadd local hour "Yes", replace
                          estadd local LoanId "Yes", replace
                  est store AutoSwitching
                  
                  nlcom -_b[l.PercentAutoBid]/(2*_b[l.c.PercentAutoBid#l.c.PercentAutoBid])
                
                  margins, at(l.PercentAutoBid = (0(0.1)1))
                  set scheme s1color
                  marginsplot, /*
                  */ plot1opts(lc(black) lp(longdash_dot)) ciopt(color(black)) plotopts(mcolor("black")) /*
                  */ xline(.786, lstyle(grid) lp(longdash_dot) lc(maroon)) xti("Lag (Share Auto Bidding)") /*
                  */ text(0.04 0.77 "Turning Point at 0.786", place(s) orient(vertical) color(black) size(small)) /*
                  */ yti("Pr(Switch to Automatic = 1)")  title("Panel B: Switching to Automatic") /*
                  */ name(plot1, replace)  addplot(lfit meansharpe lp if tag, sort lc(red) yaxis(2) ///
                     yscale(alt) ytitle("Predicted Sharpe Ratios", axis(2) color(red)) ///
                     ylab(, labcolor(red) axis(2))leg(off))
              Click image for larger version

Name:	Graph.png
Views:	1
Size:	41.6 KB
ID:	1685002

              Comment


              • #8
                Thank you Andrew for your time and efforts.

                Comment


                • #9
                  Note that this topic was subsequently revised and reposted at

                  https://www.statalist.org/forums/for...ng-marginsplot

                  Comment

                  Working...
                  X