Announcement

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

  • Coefplot multiple variables in mutliple models

    Dear Stata users,

    I want to coefplot two variables (var1_x and var2_x) in the same graph across different models. For each month of the year (noted x), I run one regression. Thus, I run the following set of regressions:

    Code:
    reg y var1_1 var2_1 controls
    eststo Jan
    reg y var1_2 var2_2 controls
    eststo Feb
    reg y var1_3 var2_3 controls
    eststo Mar
    ...
    reg y var1_12 var2_12 controls
    eststo Dec
    
    coefplot  (jan) (feb) (ma) ... (dec), keep(var1* var2*) ylabel aseq swapnames xline(0)
    The problem is that I obtain two labels for each monthly variable and a doubled y-axis scale in the coefplot. How can I have only one label per variable in a unique coefplot (and only one scale for the whole graph)?

    Sorry if the topic has already been treated; I don't find any help in the forum.





    Last edited by rouault eleonor; 25 Jul 2023, 13:39.

  • #2
    coefplot is from SSC (FAQ Advice #12). Reproducible example??

    Comment


    • #3
      First, -ylabel- is not an option in coefplot and isn't this results of the -swapname- option?

      Compare
      Code:
      clear*
      webuse grunfeld
      qui {
          reg invest mvalue kstock if year == 1935
          eststo y1
          reg invest mvalue kstock if year == 1936
          eststo y2
          reg invest mvalue kstock if year == 1937
          eststo y3
          reg invest mvalue kstock if year == 1938
          eststo y4
          reg invest mvalue kstock if year == 1939 
          eststo y5
      }
      coefplot  (y1) (y2) (y3) (y4) (y5),  /// 
          keep(mvalue kstock) aseq xline(0) name(gr1,replace) 
      
      coefplot  (y1) (y2) (y3) (y4) (y5),  /// 
          keep(mvalue kstock)  swapnames xaseq line(0)

      Comment


      • #4
        Thank you for your responses.

        Unfortunately, the option xaseq seems to be not allowed (r(198) error).

        This is more precisely what I want:



        Click image for larger version

Name:	example_graph.jpg
Views:	1
Size:	9.1 KB
ID:	1722461
        I tried to reshape the data you use Scott, to adapt to what I look for.

        Code:
        clear*
        webuse grunfeld
        keep if company==1
        expand 12
        bysort year : gen month = _n
        qui {
            reg invest mvalue kstock if month== 1
            eststo jan
            reg invest mvalue kstock if month== 2
            eststo feb
            reg invest mvalue kstock if month== 3
            eststo mar
            reg invest mvalue kstock if month== 4
            eststo apr
            reg invest mvalue kstock if month== 5
            eststo may
        }
        coefplot  (jan) (feb) (feb) (mar) (apr) (may),  ///
            keep(mvalue kstock) aseq name(gr1,replace)
        But mvalue and stock are separated. I would prefer for each month to have both variables estimates.

        Maybe I should rely on matrix ?

        I'm using Stata16
        Last edited by rouault eleonor; 01 Aug 2023, 04:31.

        Comment

        Working...
        X