Announcement

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

  • Coefplot: Labelling interactions with a month-year date

    Hello,

    I am using the command coefplot and need to label the axis for an interaction between a time dummy and a continuous regressor. So the model looks like:

    reghdfe ddebt i.period#c.shock, a(period state)

    I want to label the interaction term i.period#c.shock but only using the date (i.e. the variable "period"), which is formatted as year-month (%tm).

    I've read the post: https://www.statalist.org/forums/for...d-interactions

    Based on that, I created a regular expression to rename the interaction coefficients as follows:

    coefplot, keep(*.period#c.shock) vertical rename(^([0-9][0-9][0-9]).period#c.shock$ = \1, regex)

    The problem is I get the labels in numeric format (650, 651), not in date format (2014m3, 2014m4). Is there a way to do it using the option coeflabels()? I couldn't find the way and I have many dates to do it manually.

    Thanks for any help!

    Mariela

  • #2
    Can you provide a data example?

    Comment


    • #3
      Hello Andrew,

      Yes, I am copying the data and just run the two commands above. Thanks!

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input float(ddebt period shock) str6 state_name
       0 613  .09739853 "ags" 
       0 612  .09739853 "ags" 
       0 623  .09739853 "ags" 
       0 616  .09739853 "ags" 
       0 621  .09739853 "ags" 
       0 617  .09739853 "ags" 
       0 619  .09739853 "ags" 
       0 614  .09739853 "ags" 
       0 622  .09739853 "ags" 
       0 620  .09739853 "ags" 
       0 618  .09739853 "ags" 
       0 615  .09739853 "ags" 
       0 617  .12131932 "bc"  
       0 612  .12131932 "bc"  
       0 622  .12131932 "bc"  
       0 621  .12131932 "bc"  
       0 616  .12131932 "bc"  
       0 613  .12131932 "bc"  
       0 623  .12131932 "bc"  
       0 618  .12131932 "bc"  
       0 615  .12131932 "bc"  
       0 620  .12131932 "bc"  
       0 619  .12131932 "bc"  
       0 614  .12131932 "bc"  
       0 614  .10386167 "bcs" 
       0 618  .10386167 "bcs" 
       0 615  .10386167 "bcs" 
       0 620  .10386167 "bcs" 
       0 621  .10386167 "bcs" 
       0 613  .10386167 "bcs" 
       0 619  .10386167 "bcs" 
       0 612  .10386167 "bcs" 
       0 622  .10386167 "bcs" 
       0 617  .10386167 "bcs" 
       0 616  .10386167 "bcs" 
       0 623  .10386167 "bcs" 
       1 616  .05919579 "camp"
       1 615  .05919579 "camp"
       1 620  .05919579 "camp"
       1 617  .05919579 "camp"
       1 618  .05919579 "camp"
       1 613  .05919579 "camp"
       1 621  .05919579 "camp"
       1 612  .05919579 "camp"
       1 614  .05919579 "camp"
       1 622  .05919579 "camp"
       1 619  .05919579 "camp"
       1 623  .05919579 "camp"
       0 615   .0766994 "coah"
       0 612   .0766994 "coah"
       0 619   .0766994 "coah"
       0 623   .0766994 "coah"
       0 617   .0766994 "coah"
       0 621   .0766994 "coah"
       0 618   .0766994 "coah"
       0 620   .0766994 "coah"
       0 614   .0766994 "coah"
       0 613   .0766994 "coah"
       0 616   .0766994 "coah"
       0 622   .0766994 "coah"
       0 615  .14029005 "col" 
       0 623  .14029005 "col" 
       0 618  .14029005 "col" 
       0 613  .14029005 "col" 
       0 616  .14029005 "col" 
       0 622  .14029005 "col" 
       0 621  .14029005 "col" 
       0 614  .14029005 "col" 
       0 619  .14029005 "col" 
       0 620  .14029005 "col" 
       0 612  .14029005 "col" 
       0 617  .14029005 "col" 
       0 621  .13756678 "chis"
       0 619  .13756678 "chis"
       0 612  .13756678 "chis"
      -1 623  .13756678 "chis"
       0 617  .13756678 "chis"
       0 613  .13756678 "chis"
       0 615  .13756678 "chis"
       0 618  .13756678 "chis"
      -1 622  .13756678 "chis"
       0 620  .13756678 "chis"
       0 614  .13756678 "chis"
       0 616  .13756678 "chis"
       0 623 -.02329298 "chih"
       0 613 -.02329298 "chih"
       0 612 -.02329298 "chih"
       0 615 -.02329298 "chih"
       0 617 -.02329298 "chih"
       0 616 -.02329298 "chih"
       0 619 -.02329298 "chih"
       0 622 -.02329298 "chih"
       0 620 -.02329298 "chih"
       0 621 -.02329298 "chih"
       0 618 -.02329298 "chih"
       0 614 -.02329298 "chih"
       0 618 .067410916 "dgo" 
       0 621 .067410916 "dgo" 
       0 623 .067410916 "dgo" 
       0 612 .067410916 "dgo" 
      end
      format %tm period

      Comment


      • #4
        Thanks for the data example. I suppose that having the interactions on the x-axis will not be ideal due to the length of the text. Therefore, I would put the labels on the y-axis. Here, I use labmask from Stata Journal, authored by Nick Cox. reghdfe is from SSC, authored by Sergio Correia and coefplot is also from SSC, authored by Ben Jann.

        Code:
        encode state_name, gen(state)
        gen sdate2= string(period, "%tm")
        *findit labmask (follow instructions to install)
        labmask period, val(sdate2)
        reghdfe ddebt i.period#c.shock, a(period state)
        coefplot, keep(*.period#c.shock)
        Result:
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	35.0 KB
ID:	1471769

        Last edited by Andrew Musau; 23 Nov 2018, 15:38.

        Comment


        • #5
          Thanks a lot! That was great, the labmask command is very helpful. I also added coeflabel( , truncate(6)) because I don't want the "# shock" in the labels.

          Comment


          • #6
            Another way using regular expressions:

            Code:
             coefplot, keep(*.period#c.shock) rename(#c.shock = \1, regex)

            Comment


            • #7
              It works better, thank you very much!

              Comment

              Working...
              X