Announcement

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

  • Problem plotting coefplot - how to display coefs from different models

    I am trying to plot coefficients from different models and I have hard time displaying them. est 1 - est 5 do not have the expmass # crp variable, only expmass. est 6 - est 10 have the interaction term. How can I display them together grouped by dependent variable? Also, how can I organize graphs so they are not all squeezed?

    Code:
    coefplot (est1, keep(*.expmass) label(Baseline model)) /// (est6), keep(*.expmass#*.crp) label(Including critical period interaction term) xline(0) ///
    || (est2, keep(*.expmass) label(Baseline model)) /// (est7), keep(*.expmass#*.crp) label(Including critical period interaction term) xline(0) ///
    || (est3, keep(*.expmass) label(Baseline model)) /// (est8), keep(*.expmass#*.crp) label(Including critical period interaction term) xline(0) ///
    || (est4, keep(*.expmass) label(Baseline model)) /// (est9), keep(*.expmass#*.crp) label(Including critical period interaction term) xline(0) ///
    || (est5, keep(*.expmass) label(Baseline model)) /// (est10), keep(*.expmass#*.crp) label(Including critical period interaction term) xline(0) ///
    bylabels("Trust in Central Government" "Trust in Congress" "Trust in Supreme Court" "Trust in Military" "Trust in Blue House")

    Click image for larger version

Name:	Graph.jpg
Views:	1
Size:	204.3 KB
ID:	1652925
    Last edited by Eunice Kim; 03 Mar 2022, 19:21.

  • #2
    coefplot is from SSC (FAQ Advice #12). Present a reproducible example as outlined in the same FAQ Advice for any code suggestions. Also clarify whether you want the plots overlaid or in separate graphs, but combined.

    Comment


    • #3
      I can't upload a reproducible example because I don't know how. For the plots, I have five dependent variables so I would like to have three above and two below.

      Comment


      • #4
        So estimates 1 and 6 correspond to one DV, 2 and 7, and so on?

        Comment


        • #5
          You should shorten your variable labels and remove -nolab- in the code below. Choose your favorite scheme, I use the plain s1mono below.

          Code:
          sysuse auto, clear
          rename (price foreign) (expmass crp)
          estimates clear
          foreach var in mpg turn disp gear weight{
              eststo: regress `var' expmass
          }
          foreach var in mpg turn disp gear weight{
              eststo: regress `var' c.expmass##i.crp
          }
           set scheme s1mono
           coefplot (est1, label(Baseline) keep(expmass)) (est6, label(Interaction) keep(*.expmass)), bylabel("Trust in Central Government")   ///
           || (est2, keep(expmass))           (est7, keep(*.expmass))         , bylabel("Trust in Congress")  ///
           || (est3, keep(expmass))           (est8, keep(*.expmass))         , bylabel( "Trust in Supreme Court")  ///
           || (est4, keep(expmass))           (est9, keep(*.expmass))         , bylabel("Trust in Military")  ///
           || (est5, keep(expmass))           (est10, keep(*.expmass))        , bylabel("Trust in Blue House")  ///
           ||,  xline(0) byopts(xrescale) nolab subtitle(, size(small))
          Res.:

          Click image for larger version

Name:	Graph.png
Views:	1
Size:	40.7 KB
ID:	1652979

          Comment


          • #6
            Wow, thank you. I actually solved the problem on my own but I had to use keep instead of drop, and struggled with removing fixed effects. I had to spell out all the variables that I wanted to drop which was inefficient. I will study your code as well.

            Comment


            • #7
              Dear sir,
              I am using this coefplot command to plot the earning loss of households and individuals who switch to informal employment. Command is as follows:

              xtreg relative_ind_income i.WAVE##i.informal_switch if relative_ind_income <100, fe
              margins , at(WAVE=(1(1)6) informal_switch == 1) post
              est store ind_income
              xtreg relative_hh_income i.WAVE##i.informal_switch if relative_ind_income <100, fe
              margins , at(WAVE=(1(1)6) informal_switch == 1) post
              est store hh_income
              1._at : WAVE = 1
              informal_switch = 1

              2._at : WAVE = 2
              informal_switch = 1

              3._at : WAVE = 3
              informal_switch = 1

              4._at : WAVE = 4
              informal_switch = 1

              5._at : WAVE = 5
              informal_switch = 1

              6._at : WAVE = 6
              informal_switch = 1

              ------------------------------------------------------------------------------
              | Delta-method
              | Margin Std. Err. z P>|z| [95% Conf. Interval]
              -------------+----------------------------------------------------------------
              _at |
              1 | -.6453102 .0100681 -64.09 0.000 -.6650433 -.6255772
              2 | -.4464381 .0059056 -75.60 0.000 -.4580129 -.4348633
              3 | -.4274499 .0048168 -88.74 0.000 -.4368907 -.4180092
              4 | -.4072269 .0053484 -76.14 0.000 -.4177097 -.3967442
              5 | -.4296205 .0055663 -77.18 0.000 -.4405302 -.4187107
              6 | -.3965148 .0052819 -75.07 0.000 -.4068671 -.3861624
              ------------------------------------------------------------------------------
              1._at : WAVE = 1
              informal_switch = 1

              2._at : WAVE = 2
              informal_switch = 1

              3._at : WAVE = 3
              informal_switch = 1

              4._at : WAVE = 4
              informal_switch = 1

              5._at : WAVE = 5
              informal_switch = 1

              6._at : WAVE = 6
              informal_switch = 1

              ------------------------------------------------------------------------------
              | Delta-method
              | Margin Std. Err. z P>|z| [95% Conf. Interval]
              -------------+----------------------------------------------------------------
              _at |
              1 | -.2526669 .0079061 -31.96 0.000 -.2681625 -.2371712
              2 | -.3234949 .0046375 -69.76 0.000 -.3325842 -.3144056
              3 | -.2660269 .0037825 -70.33 0.000 -.2734404 -.2586134
              4 | -.2522753 .0041999 -60.07 0.000 -.2605071 -.2440436
              5 | -.2896958 .004371 -66.28 0.000 -.2982628 -.2811288
              6 | -.2299287 .0041477 -55.44 0.000 -.238058 -.2217994
              ------------------------------------------------------------------------------
              Now when I am plotting it using coefplot command as follows:
              coefplot (ind_income, recast(line) lpattern(dot) lcolor(red)) (hh_income, recast(line) lpattern (dash) lcolor(blue)), at xtitle("Wave")
              income_loss.gph
              Plot is not coming as expected with wave at X-axis from Wave 1 to wave 6 and percentage fall in income on Y-axis . Please tell me what is going wrong in it?
              Attached Files
              Last edited by Kumari Gunjan; 05 Mar 2022, 00:50.

              Comment


              • #8
                In addition to above question, Can I put value label as we can put in excel.
                Click image for larger version

Name:	excel_graph.png
Views:	1
Size:	12.2 KB
ID:	1653111
                .

                Comment


                • #9
                  Please provide a data example by copying and pasting the result of the following:

                  Code:
                  dataex relative_ind_income  relative_hh_income WAVE informal_switch

                  Plot is not coming as expected with wave at X-axis from Wave 1 to wave 6 and percentage fall in income on Y-axis . Please tell me what is going wrong in it?
                  Also explain what your expectation is and how your graph diverts from this.

                  Comment


                  • #10
                    Thank you very much for the quick response. I have run the dataex code and pasted the data below.
                    Also explain what your expectation is and how your graph diverts from this
                    In post #8 , I have shared the excel graph, where on X-axis, I have plotted Waves and Y- axis there is percentage fall in Income. I want to plot like that in stata from the margins of the regression. However, in stata plotting, Waves are not as expected. Wave is not in ascending order like 1, 2, 3, 4, 5, 6. I don't know, why it is in decimal point. Also, I want to put data labels on the line graph so that we can clearly see, how much the fall is.

                    Code:
                    * Example generated by -dataex-. To install: ssc install dataex
                    clear
                    input float(relative_ind_income relative_hh_income) long WAVE float informal_switch
                       .57763267      .2384452 1 0
                       .07849587    -.28328055 3 0
                        .4010792    -.14046785 5 0
                        .4378089    -.26997036 6 0
                        .4553692      .0601833 2 0
                        .3890637    -.14406855 4 0
                      -.12770739     2.2297213 6 0
                        .3097085      1.659728 4 0
                      -.23355877      1.443431 2 1
                       .02184152      1.768116 3 0
                       -.9999435    -.20580065 6 1
                       -.3776415    -.46635565 3 1
                       -.2682778     -.0981657 5 0
                        .3321722     .06582866 4 0
                               .             . 1 0
                      -.39827055     -.3993414 6 0
                               .             . 4 0
                        -.374245     -.3359605 1 0
                       -.4488132     -.4139407 2 1
                      -.24039973    -.24515453 6 0
                       -.1613394    -.16149884 3 0
                      -.01719932    -.02135299 4 0
                      -.09016548    -.06895828 5 0
                       -.9999817     -.2192459 3 1
                       -.9999817     .05430881 6 1
                       -.9999817   -.001545177 4 1
                       -.9999817    -.39042935 1 0
                       -.9999817    -.06666511 2 1
                       -.9999817    .023331463 5 1
                       -.6185784     -.6186016 6 1
                       -.7345261     -.7345536 5 1
                       -.6883055     -.6883313 3 1
                       -.5148732     -.5139374 1 0
                       -.6737339     -.6726396 2 1
                       -.6204531     -.6204764 4 1
                       .05754379      .0520442 6 0
                      -.06732101    -.07217798 5 0
                               .             . 1 0
                               .             . 5 1
                       .06995392      .2484161 4 0
                               .             . 1 0
                        1.492745     1.4721355 6 0
                        .8599021      .8445152 5 0
                        .8459786      .8307066 3 0
                       1.1413132     1.1236039 4 0
                        .2794276     .27560142 1 0
                      -.50505954      -.280274 1 0
                       -.9999084     .14002201 3 1
                       -.9999084     .10589907 2 1
                       -.9999084     -.3738379 6 1
                       -.9999084     .16424343 4 1
                       -.9999084    -.13294303 5 1
                       .08138853    -.01945679 6 0
                      -.25112954     -.3188605 3 0
                      -.08593335    -.08492432 4 0
                       -.4954541     -.4300996 1 0
                    -.0010969884    -.01035253 5 0
                       -.5105694     -.5360176 2 1
                       -.4406608     -.5346793 6 1
                       -.4190526     -.6924468 3 0
                       -.6604465     -.7241264 2 1
                      -.27460092     -.3117908 5 0
                       -.6404106     -.5346793 6 1
                       -.7957131     -.7241264 2 1
                       -.3536065     -.3117908 5 0
                     -.073916554     -.2429849 4 0
                      -.04404749 -.00011844705 1 0
                       -.3360233     -.2429849 4 0
                       .02804545 -.00011844705 1 0
                       -.3594687    -.36403415 6 0
                       -.9999239    -.48514825 3 1
                       -.9999239    -.02927604 1 1
                       -.3969605      .1492382 2 1
                       -.9999239    -.50967234 5 1
                       -.9999239     -.4503448 4 1
                       -.9999239     -.6608148 6 1
                        .1739963     .16950054 6 0
                        .2195562     .21492277 3 0
                      .036230642     .03225984 4 0
                       .18331215      .1787809 5 0
                       .03082899     -.6494085 3 0
                       .07878816      .1518326 1 0
                       .07878837      .1518326 1 0
                       -.0976001     .07590368 1 0
                       -.4131354    -.29623905 6 1
                     -.012573314     -.3677794 4 1
                       -.4618414    -.57799643 5 1
                       -.3557649     -.3411665 3 1
                       -.9999149     -.3677794 4 1
                       -.3127489     -.3411665 3 1
                        .3814456     .07590368 1 0
                      -.10907577    -.29623905 6 1
                       -.7901765    -.57799643 5 1
                       -.4174171     -.5869403 6 0
                               .             . 4 0
                               .             . 1 0
                        -.710103     -.7738813 3 0
                       -.3865501     -.3814096 1 0
                        .3829573     .37142465 3 0
                       .37767595      .3661871 4 0
                    end
                    label values WAVE WAVE
                    label def WAVE 1 "Q1_20", modify
                    label def WAVE 2 "Q2_20", modify
                    label def WAVE 3 "Q3_20", modify
                    label def WAVE 4 "Q1_21", modify
                    label def WAVE 5 "Q2_21", modify
                    label def WAVE 6 "Q3_21", modify
                    Last edited by Kumari Gunjan; 05 Mar 2022, 11:02.

                    Comment


                    • #11
                      Thanks. I would suggest that you place the margins estimates in the dataset and graph using twoway. It is much more customizable.


                      Code:
                      * Example generated by -dataex-. For more info, type help dataex
                      clear
                      input float(relative_ind_income relative_hh_income) long WAVE float informal_switch byte(_est_ind_income _est_hh_income) float id
                         -.9999817    -.39042935 1 0 1 1  1
                         -.9999239    -.02927604 1 1 1 1  2
                         -.5148732     -.5139374 1 0 1 1  3
                        -.50505954      -.280274 1 0 1 1  4
                         -.4954541     -.4300996 1 0 1 1  5
                         -.3865501     -.3814096 1 0 1 1  6
                          -.374245     -.3359605 1 0 1 1  7
                         -.0976001     .07590368 1 0 1 1  8
                        -.04404749 -.00011844705 1 0 1 1  9
                         .02804545 -.00011844705 1 0 1 1 10
                         .07878816      .1518326 1 0 1 1 11
                         .07878837      .1518326 1 0 1 1 12
                          .2794276     .27560142 1 0 1 1 13
                          .3814456     .07590368 1 0 1 1 14
                         .57763267      .2384452 1 0 1 1 15
                                 .             . 1 0 0 0 16
                                 .             . 1 0 0 0 17
                                 .             . 1 0 0 0 18
                                 .             . 1 0 0 0 19
                         -.9999817    -.06666511 2 1 1 1  1
                         -.9999084     .10589907 2 1 1 1  2
                         -.7957131     -.7241264 2 1 1 1  3
                         -.6737339     -.6726396 2 1 1 1  4
                         -.6604465     -.7241264 2 1 1 1  5
                         -.5105694     -.5360176 2 1 1 1  6
                         -.4488132     -.4139407 2 1 1 1  7
                         -.3969605      .1492382 2 1 1 1  8
                        -.23355877      1.443431 2 1 1 1  9
                          .4553692      .0601833 2 0 1 1 10
                         -.9999817     -.2192459 3 1 1 1  1
                         -.9999239    -.48514825 3 1 1 1  2
                         -.9999084     .14002201 3 1 1 1  3
                          -.710103     -.7738813 3 0 1 1  4
                         -.6883055     -.6883313 3 1 1 1  5
                         -.4190526     -.6924468 3 0 1 1  6
                         -.3776415    -.46635565 3 1 1 1  7
                         -.3557649     -.3411665 3 1 1 1  8
                         -.3127489     -.3411665 3 1 1 1  9
                        -.25112954     -.3188605 3 0 1 1 10
                         -.1613394    -.16149884 3 0 1 1 11
                         .02184152      1.768116 3 0 1 1 12
                         .03082899     -.6494085 3 0 1 1 13
                         .07849587    -.28328055 3 0 1 1 14
                          .2195562     .21492277 3 0 1 1 15
                          .3829573     .37142465 3 0 1 1 16
                          .8459786      .8307066 3 0 1 1 17
                         -.9999817   -.001545177 4 1 1 1  1
                         -.9999239     -.4503448 4 1 1 1  2
                         -.9999149     -.3677794 4 1 1 1  3
                         -.9999084     .16424343 4 1 1 1  4
                         -.6204531     -.6204764 4 1 1 1  5
                         -.3360233     -.2429849 4 0 1 1  6
                        -.08593335    -.08492432 4 0 1 1  7
                       -.073916554     -.2429849 4 0 1 1  8
                        -.01719932    -.02135299 4 0 1 1  9
                       -.012573314     -.3677794 4 1 1 1 10
                        .036230642     .03225984 4 0 1 1 11
                         .06995392      .2484161 4 0 1 1 12
                          .3097085      1.659728 4 0 1 1 13
                          .3321722     .06582866 4 0 1 1 14
                         .37767595      .3661871 4 0 1 1 15
                          .3890637    -.14406855 4 0 1 1 16
                         1.1413132     1.1236039 4 0 1 1 17
                                 .             . 4 0 0 0 18
                                 .             . 4 0 0 0 19
                         -.9999817    .023331463 5 1 1 1  1
                         -.9999239    -.50967234 5 1 1 1  2
                         -.9999084    -.13294303 5 1 1 1  3
                         -.7901765    -.57799643 5 1 1 1  4
                         -.7345261     -.7345536 5 1 1 1  5
                         -.4618414    -.57799643 5 1 1 1  6
                         -.3536065     -.3117908 5 0 1 1  7
                        -.27460092     -.3117908 5 0 1 1  8
                         -.2682778     -.0981657 5 0 1 1  9
                        -.09016548    -.06895828 5 0 1 1 10
                        -.06732101    -.07217798 5 0 1 1 11
                      -.0010969884    -.01035253 5 0 1 1 12
                         .18331215      .1787809 5 0 1 1 13
                          .4010792    -.14046785 5 0 1 1 14
                          .8599021      .8445152 5 0 1 1 15
                                 .             . 5 1 0 0 16
                         -.9999817     .05430881 6 1 1 1  1
                         -.9999435    -.20580065 6 1 1 1  2
                         -.9999239     -.6608148 6 1 1 1  3
                         -.9999084     -.3738379 6 1 1 1  4
                         -.6404106     -.5346793 6 1 1 1  5
                         -.6185784     -.6186016 6 1 1 1  6
                         -.4406608     -.5346793 6 1 1 1  7
                         -.4174171     -.5869403 6 0 1 1  8
                         -.4131354    -.29623905 6 1 1 1  9
                        -.39827055     -.3993414 6 0 1 1 10
                         -.3594687    -.36403415 6 0 1 1 11
                        -.24039973    -.24515453 6 0 1 1 12
                        -.12770739     2.2297213 6 0 1 1 13
                        -.10907577    -.29623905 6 1 1 1 14
                         .05754379      .0520442 6 0 1 1 15
                         .08138853    -.01945679 6 0 1 1 16
                          .1739963     .16950054 6 0 1 1 17
                          .4378089    -.26997036 6 0 1 1 18
                          1.492745     1.4721355 6 0 1 1 19
                      end
                      label values WAVE WAVE
                      label def WAVE 1 "Q1_20", modify
                      label def WAVE 2 "Q2_20", modify
                      label def WAVE 3 "Q3_20", modify
                      label def WAVE 4 "Q1_21", modify
                      label def WAVE 5 "Q2_21", modify
                      label def WAVE 6 "Q3_21", modify
                      
                      xtset id WAVE
                      xtreg relative_ind_income i.WAVE##i.informal_switch if relative_ind_income <100, fe
                      margins , at(WAVE=(1(1)6) informal_switch == 1) post
                      est store ind_income
                      xtreg relative_hh_income i.WAVE##i.informal_switch if relative_ind_income <100, fe
                      margins , at(WAVE=(1(1)6) informal_switch == 1) post
                      est store hh_income
                      
                      *START HERE
                      est restore ind_income
                      mat b1= e(b)'
                      est restore hh_income
                      mat b2= e(b)'
                      mat b= b1,b2
                      svmat b
                      gen W=_n if !missing(b1)
                      format b1 b2 %3.2f
                      set scheme s1color
                      tw (scatter b1 W, connect(l) mc(none) mlab(b1) mlabpos(12)) (scatter b2 W, connect(l) mc(none) ///
                      mlab(b2) mlabpos(12)), xlab(1 "Wave 1" 2 "Wave 2" 3 "Wave 3" 4 "Wave 4" 5 "Wave 5" 6 "Wave 6") ///
                      xsc(r(0.5 6.5) alt) ysc(r(. 0.25)) xtitle("") legend(order(1 "Individual Income" 2 "Household Income"))

                      Click image for larger version

Name:	Graph.png
Views:	1
Size:	36.3 KB
ID:	1653182

                      Comment


                      • #12
                        Thank you very much! It worked for me. I have one more question to ask. Is there a way to include the "CLASS INTERVAL" of margins in two-way line graph?

                        Comment


                        • #13
                          Do you mean confidence intervals? You are almost going back to the output of marginsplot. See combomarginsplot from SSC which allows you to combine multiple marginsplots. Otherwise, here is a way with twoway and offsetting the confidence intervals.

                          Code:
                          * Example generated by -dataex-. For more info, type help dataex
                          clear
                          input float(relative_ind_income relative_hh_income) long WAVE float informal_switch byte(_est_ind_income _est_hh_income) float id
                             -.9999817    -.39042935 1 0 1 1  1
                             -.9999239    -.02927604 1 1 1 1  2
                             -.5148732     -.5139374 1 0 1 1  3
                            -.50505954      -.280274 1 0 1 1  4
                             -.4954541     -.4300996 1 0 1 1  5
                             -.3865501     -.3814096 1 0 1 1  6
                              -.374245     -.3359605 1 0 1 1  7
                             -.0976001     .07590368 1 0 1 1  8
                            -.04404749 -.00011844705 1 0 1 1  9
                             .02804545 -.00011844705 1 0 1 1 10
                             .07878816      .1518326 1 0 1 1 11
                             .07878837      .1518326 1 0 1 1 12
                              .2794276     .27560142 1 0 1 1 13
                              .3814456     .07590368 1 0 1 1 14
                             .57763267      .2384452 1 0 1 1 15
                                     .             . 1 0 0 0 16
                                     .             . 1 0 0 0 17
                                     .             . 1 0 0 0 18
                                     .             . 1 0 0 0 19
                             -.9999817    -.06666511 2 1 1 1  1
                             -.9999084     .10589907 2 1 1 1  2
                             -.7957131     -.7241264 2 1 1 1  3
                             -.6737339     -.6726396 2 1 1 1  4
                             -.6604465     -.7241264 2 1 1 1  5
                             -.5105694     -.5360176 2 1 1 1  6
                             -.4488132     -.4139407 2 1 1 1  7
                             -.3969605      .1492382 2 1 1 1  8
                            -.23355877      1.443431 2 1 1 1  9
                              .4553692      .0601833 2 0 1 1 10
                             -.9999817     -.2192459 3 1 1 1  1
                             -.9999239    -.48514825 3 1 1 1  2
                             -.9999084     .14002201 3 1 1 1  3
                              -.710103     -.7738813 3 0 1 1  4
                             -.6883055     -.6883313 3 1 1 1  5
                             -.4190526     -.6924468 3 0 1 1  6
                             -.3776415    -.46635565 3 1 1 1  7
                             -.3557649     -.3411665 3 1 1 1  8
                             -.3127489     -.3411665 3 1 1 1  9
                            -.25112954     -.3188605 3 0 1 1 10
                             -.1613394    -.16149884 3 0 1 1 11
                             .02184152      1.768116 3 0 1 1 12
                             .03082899     -.6494085 3 0 1 1 13
                             .07849587    -.28328055 3 0 1 1 14
                              .2195562     .21492277 3 0 1 1 15
                              .3829573     .37142465 3 0 1 1 16
                              .8459786      .8307066 3 0 1 1 17
                             -.9999817   -.001545177 4 1 1 1  1
                             -.9999239     -.4503448 4 1 1 1  2
                             -.9999149     -.3677794 4 1 1 1  3
                             -.9999084     .16424343 4 1 1 1  4
                             -.6204531     -.6204764 4 1 1 1  5
                             -.3360233     -.2429849 4 0 1 1  6
                            -.08593335    -.08492432 4 0 1 1  7
                           -.073916554     -.2429849 4 0 1 1  8
                            -.01719932    -.02135299 4 0 1 1  9
                           -.012573314     -.3677794 4 1 1 1 10
                            .036230642     .03225984 4 0 1 1 11
                             .06995392      .2484161 4 0 1 1 12
                              .3097085      1.659728 4 0 1 1 13
                              .3321722     .06582866 4 0 1 1 14
                             .37767595      .3661871 4 0 1 1 15
                              .3890637    -.14406855 4 0 1 1 16
                             1.1413132     1.1236039 4 0 1 1 17
                                     .             . 4 0 0 0 18
                                     .             . 4 0 0 0 19
                             -.9999817    .023331463 5 1 1 1  1
                             -.9999239    -.50967234 5 1 1 1  2
                             -.9999084    -.13294303 5 1 1 1  3
                             -.7901765    -.57799643 5 1 1 1  4
                             -.7345261     -.7345536 5 1 1 1  5
                             -.4618414    -.57799643 5 1 1 1  6
                             -.3536065     -.3117908 5 0 1 1  7
                            -.27460092     -.3117908 5 0 1 1  8
                             -.2682778     -.0981657 5 0 1 1  9
                            -.09016548    -.06895828 5 0 1 1 10
                            -.06732101    -.07217798 5 0 1 1 11
                          -.0010969884    -.01035253 5 0 1 1 12
                             .18331215      .1787809 5 0 1 1 13
                              .4010792    -.14046785 5 0 1 1 14
                              .8599021      .8445152 5 0 1 1 15
                                     .             . 5 1 0 0 16
                             -.9999817     .05430881 6 1 1 1  1
                             -.9999435    -.20580065 6 1 1 1  2
                             -.9999239     -.6608148 6 1 1 1  3
                             -.9999084     -.3738379 6 1 1 1  4
                             -.6404106     -.5346793 6 1 1 1  5
                             -.6185784     -.6186016 6 1 1 1  6
                             -.4406608     -.5346793 6 1 1 1  7
                             -.4174171     -.5869403 6 0 1 1  8
                             -.4131354    -.29623905 6 1 1 1  9
                            -.39827055     -.3993414 6 0 1 1 10
                             -.3594687    -.36403415 6 0 1 1 11
                            -.24039973    -.24515453 6 0 1 1 12
                            -.12770739     2.2297213 6 0 1 1 13
                            -.10907577    -.29623905 6 1 1 1 14
                             .05754379      .0520442 6 0 1 1 15
                             .08138853    -.01945679 6 0 1 1 16
                              .1739963     .16950054 6 0 1 1 17
                              .4378089    -.26997036 6 0 1 1 18
                              1.492745     1.4721355 6 0 1 1 19
                          end
                          label values WAVE WAVE
                          label def WAVE 1 "Q1_20", modify
                          label def WAVE 2 "Q2_20", modify
                          label def WAVE 3 "Q3_20", modify
                          label def WAVE 4 "Q1_21", modify
                          label def WAVE 5 "Q2_21", modify
                          label def WAVE 6 "Q3_21", modify
                          
                          xtset id WAVE
                          xtreg relative_ind_income i.WAVE##i.informal_switch if relative_ind_income <100, fe
                          margins , at(WAVE=(1(1)6) informal_switch == 1) post
                          mat b1= (r(table)[1, 1...]\ r(table)[5..6, 1...])'
                          xtreg relative_hh_income i.WAVE##i.informal_switch if relative_ind_income <100, fe
                          margins , at(WAVE=(1(1)6) informal_switch == 1) post
                          mat b2= (r(table)[1, 1...]\ r(table)[5..6, 1...])'
                          mat b= b1,b2
                          svmat b
                          gen W=_n if !missing(b1)
                          gen W1 = W+0.05
                          gen W2= W-0.05
                          format b? %3.2f
                          set scheme s1color
                          
                          twoway (rspike b2 b3 W1, sort pstyle(ci) color(blue)) ///
                          (rspike b5 b6 W2, sort pstyle(ci) color(red)) ///
                          (connected b1 W1, lp(solid) lc(blue) msy(none) mlab(b1) mlabpos(6)) ///
                          (connected b4 W2, lp(dash) lc(red) msy(none) mlab(b4) mlabpos(12)), ///
                          title("Adjusted Predictions with 95% CIs") ytitle("Linear Prediction") ///
                          xla(, valuelabel) xsc(r(0.5 6.5) alt) legend(pos(5) ring(0) col(1) ///
                          region(lwidth(none)) order(1 "Individual Income" 2 "Household Income")) ///
                          xlab(1 "Wave 1" 2 "Wave 2" 3 "Wave 3" 4 "Wave 4" 5 "Wave 5" 6 "Wave 6")
                          Click image for larger version

Name:	Graph.png
Views:	1
Size:	34.9 KB
ID:	1653228

                          Comment


                          • #14
                            Hello Andrew,
                            Your responses helped me a lot. I have one more query. Can you help me in plotting the means of Individual income by informal switch==1 and informal switch ==0 for all the WAVEs. Actually, I leant from this platform that collapsing the mean values by category I want and then running the code for plotting. But I have to plot for many categories such as demographics also. It would be nice if you can provide some simple codes to me.

                            I want graph of mean ind_income by switch_informal for WAVE. Then I would like to graph mean income for male and female if switch_informal==1.
                            Code:
                             * Example generated by -dataex-. To install: ssc install dataex clear input float(ind_income ind_wage) long WAVE float switched_informal long sex 19283.504 19283.504 0 0 0 30422.863 30422.863 1 0 0  28065.07  28065.07 2 0 0  20797.26  20797.26 3 0 0 26786.404 26786.404 4 0 0  27018.12  27018.12 5 0 0  27726.43  27726.43 6 0 0  17196.21  17196.21 0 1 0  13179.65  13179.65 2 1 0 17571.824 17571.824 3 1 0 22522.334 22522.334 4 1 0     15000     15000 6 1 0  29033.45 23133.246 0 0 0 23686.174         0 1 0 0 16711.127         0 4 0 0  27955.92         0 5 0 0  27726.43         0 6 0 0  13708.59  13708.59 0 0 1  17701.98  17701.98 0 1 0         0         0 1 1 0 1608.7517 1608.7517 2 1 0   11016.6   11016.6 3 1 0  23582.42  23582.42 4 1 0 12952.664 12952.664 5 1 0         0         0 6 1 0  9103.876  9103.876 0 0 0         0         0 1 0 0         0         0 2 0 0         0         0 3 0 0         0         0 4 0 0         0         0 5 0 0         0         0 6 0 0  32767.17  32767.17 0 0 0         .         . 1 0 0         .         . 4 0 0 19716.574 19716.574 6 0 0  9734.009  9734.009 0 1 0   6090.73   6090.73 1 1 0  5364.809  5364.809 2 1 0  8163.368  8163.368 3 1 0  9566.573  9566.573 4 1 0  8856.247  8856.247 5 1 0  7393.715  7393.715 6 1 0  54729.95  54611.95 0 1 0         0         0 1 1 0         0         0 2 1 0         0         0 3 1 0         0         0 4 1 0         0         0 5 1 0         0         0 6 1 0  26655.48  26655.48 0 1 0 12930.771 12930.771 1 1 0  8696.105  8696.105 2 1 0  8307.677  8307.677 3 1 0 10116.385 10116.385 4 1 0    7075.6    7075.6 5 1 0 10166.358 10166.358 6 1 0 17478.453 17478.453 0 0 0  16301.72  16301.72 5 0 0 18484.287 18484.287 6 0 0  5359.365  5359.365 0 1 0         .         . 1 1 0  5734.343  5734.343 4 1 0         .         . 5 1 0  3349.603  3349.603 0 0 0         .         . 1 0 0         .         . 0 0 1  26447.07 26421.387 0 0 0  33837.39  33837.39 1 0 0  48821.57  48821.57 3 0 0   56632.6   56632.6 4 0 0  49189.82  49189.82 5 0 0   65927.3   65927.3 6 0 0 22016.266 22016.266 0 0 0  10922.39  10922.39 0 1 0  5405.428  5405.428 1 1 0         0         0 2 1 0         0         0 3 1 0         0         0 4 1 0         0         0 5 1 0         0         0 6 1 0  17093.03  17093.03 0 1 0  8623.723  8623.723 1 1 0  8365.341  8365.341 2 1 0 12800.214 12800.214 3 1 0 15624.082 15624.082 4 1 0 17074.277 17074.277 5 1 0 18484.287 18484.287 6 1 0  30844.33  30844.33 0 1 0  10472.64  10472.64 2 1 0 17918.514 17918.514 3 1 0 22374.174 22374.174 5 1 0 17252.002 17252.002 6 1 0  27417.18  27417.18 0 1 0  5600.174  5600.174 2 1 0         0         0 3 1 0 17721.934 17721.934 5 1 0  9858.287  9858.287 6 1 0  6886.663  6886.663 0 0 0  6583.279  6583.279 1 0 0 end label values WAVE WAVE label def WAVE 0 "Q3_19", modify label def WAVE 1 "Q1_20", modify label def WAVE 2 "Q2_20", modify label def WAVE 3 "Q3_20", modify label def WAVE 4 "Q1_21", modify label def WAVE 5 "Q2_21", modify label def WAVE 6 "Q3_21", modify label values sex sex label def sex 1 "F", modify

                            Comment


                            • #15
                              I cannot run your dataex example. Please repost the data making sure to include at least two waves. The use of -by- implies two graphs side-by-side, i.e., for a binary variable "informal switch", one graph for informal switch==1 and another for informal switch==0. Now should you have a line graph for each wave in a particular by-graph?

                              Comment

                              Working...
                              X