Announcement

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

  • How to change coefficient labels in batch in -coefplot-, and add a specific line for event date?

    I was using the following code to create dummy variables for each year, run regression and plot the coefficients on these dummies:

    Code:
    levelsof fyear, local(years)
    foreach i in `years' {
        gen lambda`i' = 0
        replace lambda`i' = 1 if fyear == `i'
        gen dlambda`i' = d * lambda`i'
    }
    
    regress ml_w d p dlambda* 
    levelsof fyear, local(years)
    coefplot, drop(_cons d p) vertical ciopts(recast(rcap)) yline(0) msymbol(d) coeflabels(dlambda* = `years')
    Without the last option, coeflabels(dlambda* = `years'), the graph generated is
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	31.1 KB
ID:	1431077


    I got two issues:

    First, as you can see, the names of these dummy variables make the plot look horrible. How can I change the labels for all of them in batch? For example, I want something like
    Code:
    label dlambda2001  2001
    and so on.

    Second, I want to plot a vertical line at dlambda2004. How can I do this? Thanks!

  • #2
    I figured out how to change the labels, maybe useful for others:

    Code:
    levelsof fyear, local(years)
    foreach i in `years' {
        gen lambda`i' = 0
        replace lambda`i' = 1 if fyear == `i'
        gen dlambda`i' = d * lambda`i'
        label variable dlambda`i'  "`i'"
    }
    regress ml_w d p dlambda* 
    coefplot, keep(dlambda*) vertical ciopts(recast(rcap)) yline(0) msymbol(d)
    I am still not able to add the vertical line here. Hope someone can help!

    Comment


    • #3
      Hi David,

      You can use the following code to change the labels en masse.
      Code:
      forval i = 2001(1)2010 {
      label variable dlambda`i' `i'
      }
      In order to add the vertical line:
      Code:
      regress ml_w d p dlambda*
      coefplot, keep(dlambda*) vertical ciopts(recast(rcap)) yline(0) xline(4) msymbol(d)

      Comment


      • #4
        Originally posted by Matt Warkentin View Post
        Hi David,

        You can use the following code to change the labels en masse.
        Code:
        forval i = 2001(1)2010 {
        label variable dlambda`i' `i'
        }
        In order to add the vertical line:
        Code:
        regress ml_w d p dlambda*
        coefplot, keep(dlambda*) vertical ciopts(recast(rcap)) yline(0) xline(4) msymbol(d)
        Thank you, Matt! It is nice that a simple number "4" can work like this.
        A another quick question: in -coefplot-, I can use -recast(connected)- to create a line to connect points of estimated coefficients. How can I make this connecting line dashed?

        Comment


        • #5
          Hi David,

          Happy to help. To add a dashed line use the following code:
          Code:
          coefplot , addplot(line @b @at , lpat(dash)) vertical
          You can control the color or width using the suboption -lcol- or -lwidth-, for example:
          Code:
          coefplot , addplot(line @b @at , lpat(dash) lcol(red) lwidth(0.1)) vertical

          Comment

          Working...
          X