Announcement

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

  • Labeling With Coefplot and Interactions

    Hello, I am running a panel fixed effects regression where I'd like to plot the interaction effects of a 0/1 dummy with a year fixed effect. The regression ultimately looks like:
    Code:
    xtreg inc i.year i.ogj#i.year, fe
    .

    I then store important estimates using
    Code:
    estimates store interaction
    and then would like to plot using
    Code:
    coefeplot (interactions), keep(1.ogj#*year)
    .

    This works fine except the labels are tedious. They read
    "Overlays Large Field#1yearyear=1975"
    and so on. I'd like for them just to say the year, but I can't quite figure it out without manually going through them and changing them one by one. I have to run many varieties of this equation, so a quick way of doing this would be great. Any suggestions?

    (As a side note, I am on a restricted data portal and cannot post images/code here. I also cannot download any online packages that may be better).

  • #2
    Welcome to Stata Forum / Statalist.

    It is a pity you cannot share data, even a toy example, neither download files.

    In spite of that, I tried to share the help files of the user-written coefplot with you.

    http://repec.sowi.unibe.ch/stata/coe...help-file.html

    Be sure to take a look at the coeflabels option. You may wish to fiddle with it in order to reach your goal.

    Hopefully that helps.
    Best regards,

    Marcos

    Comment


    • #3
      Originally posted by justin winikoff View Post
      Hello, I am running a panel fixed effects regression where I'd like to plot the interaction effects of a 0/1 dummy with a year fixed effect. The regression ultimately looks like:
      Code:
      xtreg inc i.year i.ogj#i.year, fe
      .

      I then store important estimates using
      Code:
      estimates store interaction
      and then would like to plot using
      Code:
      coefeplot (interactions), keep(1.ogj#*year)
      .

      This works fine except the labels are tedious. They read and so on. I'd like for them just to say the year, but I can't quite figure it out without manually going through them and changing them one by one. I have to run many varieties of this equation, so a quick way of doing this would be great. Any suggestions?

      (As a side note, I am on a restricted data portal and cannot post images/code here. I also cannot download any online packages that may be better).
      As Marcos said, the coeflabels option would do it. You have to refer to the coefficients by the correct name and do them one by one, e.g.

      Code:
       
       coefeplot (interactions), keep(1.ogj#*year) coeflabel(1.ogj#1975year = "1975")
      However, I suspect that using the rename option plus regex would be easier if you've got a lot of year dummies. Do you know how to write a regular expression? They can be very powerful when used in renaming text. I think that something like this might do it:

      Code:
       
       coefeplot (interactions), keep(1.ogj#*year) rename(^1.ogj#([0-9]+)year$ = \1, regex)
      The phrase
      Code:
      ([0-9]+)
      should indicate to Stata to look for any number of digits. You could change the + to a {4} to tell it to look for 4 digits specifically. The
      Code:
      \1
      after the = sign means to substitute the matched subexpression. That might work, or you might have to play around.
      Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

      When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

      Comment


      • #4
        Hello Weiwen. Thank you for your response. I've tried both of these methods and neither works. The output is identical to what it was before.

        [EDIT] Weiwen, this worked. The problem had been that the estimates were actually stored as 1.ogj#1975.year and so on, so the "." was throwing it off. Including it in the rename works.

        Thank you so much for your help!!
        Last edited by justin winikoff; 09 Oct 2017, 11:09.

        Comment


        • #5
          Hello,

          I have a question related to this thread:
          https://www.statalist.org/forums/for...-with-coefplot

          I would be happy to get any advice.

          Thank you!

          Comment

          Working...
          X