Announcement

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

  • labeling coefplot with string

    Hi,

    I have a dataset with variables A B C D E F G H I J K L M N O P Q R S T U V W X Y Z inflow.

    I have run multiple regressions while saving the estimated coefficient as such.

    Code:
    foreach dep in A B C D E F G H I J K L M N O P Q R S T U V W X Y Z{
    reg `dep' inflow
    est sto `dep'
    }
    Then I use coefplot to plot the confidence intervals of each regression into one graph.

    Code:
    coefplot A B C D E F G H I J K L M N O P Q R S T U V W X Y Z, drop(_cons) vertical yline(0) legend(off)
    I can get the graph to appear, but I want to label the x-axis with the variable names (A B C D ...)

    How do I do this?

    Thanks in advance.

  • #2
    coefplot is from the Stata Journal, as you are asked to explain.

    Code:
    local i 1
    foreach l in `c(ALPHA)'{
        local list "`list' `i' "`l'""
        local ++i
     }
    di `"`list'"'
    This gives you

    Code:
    . di `"`list'"'
     1 "A" 2 "B" 3 "C" 4 "D" 5 "E" 6 "F" 7 "G" 8 "H" 9 "I" 10 "J" 11 "K" 12 "L" 13 "M" 14 "N" 15 "O" 16 "P" 17 "Q" 18 "R" 19 "S" 20 "T" 21 "U" 22 "V" 23 "W" 2
    > 4 "X" 25 "Y" 26 "Z"

    Include this within the -xlab()- option

    Code:
    coefplot ..., drop(_cons) vertical xlab(`list') yline(0) legend(off)

    Comment


    • #3
      Thanks for the tip. But the graph produced is not the graph I am looking for. I try to run the code as you have told me, but the results are as follows. Please note that the code is slightly different from the one posted in the first post since this is the actual code that I am using for my regressions.

      Code:
      local i 1
      foreach var in ARE ARG AUT AUS BEL BGR BRA CAN CHE CHL CHN COL CYP CZE DEU DNK DZA EST ESP FIN FRA GBR GRC HKG HRV HUN IDN IRL ISR IND ISL ITA JPN KOR LTU LUX LVA MLT MEX MYS NLD NOR NZL PER PHL POL PRT ROU RUS SAU SWE SGP SVN SVK THA TUR TWN USA EU ZAF{
      local list "`list' `i' "`var'""
      local ++i
      }
      di `"`list'"'
      
      foreach dep in ARE ARG AUT AUS BEL BGR BRA CAN CHE CHL CHN COL CYP CZE DEU DNK DZA EST ESP FIN FRA GBR GRC HKG HRV HUN IDN IRL ISR IND ISL ITA JPN KOR LTU LUX LVA MLT MEX MYS NLD NOR NZL PER PHL POL PRT ROU RUS SAU SWE SGP SVN SVK THA TUR TWN USA EU ZAF{
      reg `dep'_app inflow_gf
      est sto `dep'
      }
      
      coefplot ARE ARG AUT AUS BEL BGR BRA CAN CHE CHL CHN COL CYP CZE DEU DNK DZA EST ESP FIN FRA GBR GRC HKG HRV HUN IDN IRL ISR IND ISL ITA JPN KOR LTU LUX LVA MLT MEX MYS NLD NOR NZL PER PHL POL PRT ROU RUS SAU SWE SGP SVN SVK THA TUR TWN USA EU ZAF, drop(_cons) vertical xlab(`list') yline(0) legend(off)
      This creates a graph like this one.
      Graph.png


      The labels in the x-axis are not where I want them to be. They do not match 1-on-1 with the plotted coefficient/confidence intervals.
      I don't think the stored coefficient/confidence intervals are being recognized with a certain numerical value which is what is causing this to happen.

      Is there something I can do to fix this?

      Comment


      • #4
        I think the easiest way is to change the name of your regressor across countries. Try this (after creating the local "list"):

        Code:
        local i 1
        rename inflow_gf inflow_gf1
        foreach dep in ARE ARG AUT AUS BEL BGR BRA CAN ///
        CHE CHL CHN COL CYP CZE DEU DNK DZA EST ESP ///
        FIN FRA GBR GRC HKG HRV HUN IDN IRL ISR IND ISL ///
        ITA JPN KOR LTU LUX LVA MLT MEX MYS NLD NOR NZL ///
        PER PHL POL PRT ROU RUS SAU SWE SGP SVN SVK ///
        THA TUR TWN USA EU ZAF{
            cap rename inflow_gf`=`i'-1' inflow_gf`i'
            reg `dep'_app inflow_gf`i'
            est sto `dep'
            local ++i
        }
        coefplot ARE ARG AUT AUS BEL BGR BRA CAN CHE CHL ///
        CHN COL CYP CZE DEU DNK DZA EST ESP FIN FRA GBR ///
        GRC HKG HRV HUN IDN IRL ISR IND ISL ITA JPN KOR LTU ///
        LUX LVA MLT MEX MYS NLD NOR NZL PER PHL POL PRT ///
        ROU RUS SAU SWE SGP SVN SVK THA TUR TWN USA ///
        EU ZAF, drop(_cons) vertical xlab(`list') yline(0) legend(off)

        Comment


        • #5
          Amazing! Thanks for the help.

          Comment

          Working...
          X