Announcement

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

  • Problem with Coefplot when grouping variables from multiple models

    Hello everyone,

    I am trying to find a way, how variables can be grouped in a Coefplot with multiple models and similar variable names.

    To begin with, I am working on a dataset that contains variables measuring attitudes towards income redistribution (e.g. ideal_redis) and drivers like the perception towards social mobility (soc_mob) that may explain those attitudes. The dataset contains information across six different countries and currently comprises 7954 observations and 824 variables in total. Here is an example:


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str8 id float(ideal_redis dif_tax_top1_bot50 fin_sec soc_mob immigr2 trustsv_gov socialc_daily right_wing left_wing fem_resp eq_hh_inc5 edu_cat_1 edu_cat_3) byte(dummctry1 dummctry2 dummctry3)
    "oypkwm6r"  10.71068  55 2.2285094 2.3342535  2.914331 2.3664074 0 0 1 0 1 1 0 1 0 0
    "lu2fugw6" 2.2315383   8  3.565615  3.112338  3.642914 1.1832037 0 1 0 0 0 0 1 1 0 0
    "tuswl5ab"  5.315876  25  4.457019 2.3342535  1.821457 1.9720062 0 1 0 1 0 0 1 1 0 0
    "tr8ydsq9"  3.354943  16  2.674211  1.556169 2.1857483   3.15521 0 0 0 0 0 0 0 1 0 0
    "z89oaoun" -5.478949 -36 1.7828075  .7780845  2.914331  2.760809 0 0 0 0 0 1 0 1 0 0
    "dh56whmp"  .9688556   0 2.2285094 2.3342535 1.0928742 1.9720062 0 0 0 1 0 1 0 1 0 0
    "8y7cosz4"  7.504148  38  2.674211 2.3342535 2.5500395  2.760809 0 0 0 1 0 0 0 1 0 0
    "cfcbkxfp"   5.78357  40  4.457019 3.8904226  3.642914 3.9440124 0 1 0 1 0 1 0 1 0 0
    "qf7xnjej"  10.07989  66         .         .         . 1.9720062 0 0 0 1 1 0 1 1 0 0
    "q3bsipwq"  5.287528  42 2.2285094 1.9452113  3.642914 1.9720062 0 0 0 1 0 0 0 1 0 0
    "o0p42toh"  9.167415  49  3.565615  3.112338 2.5500395  2.760809 0 1 0 0 0 0 1 1 0 0
    "6wachra6" 1.6787767   3  2.674211 3.8904226 1.4571655 .39440125 0 1 0 1 1 0 0 1 0 0
    "m1i9sqjn"  3.523725  15         0 1.9452113  1.821457 1.9720062 0 1 0 0 0 1 0 1 0 0
    "o57zks9h"  9.175116  36 2.2285094  2.723296 2.1857483  2.760809 0 0 0 0 0 0 0 1 0 0
    "erqoabkm"  7.480872  38  3.565615  3.112338  2.914331   3.15521 0 0 0 1 1 0 0 1 0 0
    end
    label values fin_sec finsec
    label def finsec 0 "0 - Worse", modify
    label values soc_mob soc_mob
    label values immigr2 immigr2
    label values trustsv_gov trust2
    label values fem_resp fem
    label def fem 0 "Male", modify
    label def fem 1 "Female", modify
    What I observed first is the heterogeneity regarding the effect of e.g. the perception of social mobility on attitudes towards income redistribution across different groups (high-income vs. low-income or right-wing vs. left wing). To estimate these interaction effects I used the following regression command:

    Code:
    reg ideal_redis $socioeconomic_basic $exp_riskav c.fin_sec#(1.right_wing 1.left_wing 1.polit_orient_na 1.fem_resp 1.eq_hh_inc5 1.edu_cat_1 1.edu_cat_3) ///
    c.soc_mob c.soc_mob#(1.right_wing 1.left_wing 1.polit_orient_na 1.fem_resp 1.eq_hh_inc5 1.edu_cat_1 1.edu_cat_3) ///
    c.immigr2 c.immigr2#(1.right_wing 1.left_wing 1.polit_orient_na 1.fem_resp 1.eq_hh_inc5 1.edu_cat_1 1.edu_cat_3) ///
    c.trustsv_gov c.trustsv_gov#(1.right_wing 1.left_wing 1.polit_orient_na 1.fem_resp 1.eq_hh_inc5 1.edu_cat_1 1.edu_cat_3) ///
    1.socialc_daily#(1.right_wing 1.left_wing 1.polit_orient_na 1.fem_resp 1.eq_hh_inc5 1.edu_cat_1 1.edu_cat_3) ///
    c.religion#(1.right_wing 1.left_wing 1.polit_orient_na 1.fem_resp 1.eq_hh_inc5 1.edu_cat_1 1.edu_cat_3) ///
    c.reciprocity#(1.right_wing 1.left_wing 1.polit_orient_na 1.fem_resp 1.eq_hh_inc5 1.edu_cat_1 1.edu_cat_3) ///
    c.tw_exp_share c.tw_exp_share#(1.right_wing 1.left_wing 1.polit_orient_na 1.fem_resp 1.eq_hh_inc5 1.edu_cat_1 1.edu_cat_3) ///
    $social_preferences $relig_community $social_contact 1.right_wing 1.left_wing 1.polit_orient_na $dummctry, robust

    In a next step I further wanted to show, to what extend these interaction effects differ across countries. In other words, I want to find out whether e.g. people with high income differ systematically across countries in how attitudes towards income redistribution may be explained. Therefore I estimated interaction effects for each country separately with the following model:

    Code:
    foreach var in ideal_redis dif_tax_top1_bot50 {
    foreach country in DEU GBR ITA JPN SVN {
        
    reg `var' $socioeconomic_basic $exp_riskav c.fin_sec#(1.right_wing 1.left_wing 1.polit_orient_na 1.fem_resp 1.eq_hh_inc5 1.edu_cat_1 1.edu_cat_3) ///
    c.soc_mob c.soc_mob#(1.right_wing 1.left_wing 1.polit_orient_na 1.fem_resp 1.eq_hh_inc5 1.edu_cat_1 1.edu_cat_3) ///
    c.immigr2 c.immigr2#(1.right_wing 1.left_wing 1.polit_orient_na 1.fem_resp 1.eq_hh_inc5 1.edu_cat_1 1.edu_cat_3) ///
    c.trustsv_gov c.trustsv_gov#(1.right_wing 1.left_wing 1.polit_orient_na 1.fem_resp 1.eq_hh_inc5 1.edu_cat_1 1.edu_cat_3) ///
    1.socialc_daily#(1.right_wing 1.left_wing 1.polit_orient_na 1.fem_resp 1.eq_hh_inc5 1.edu_cat_1 1.edu_cat_3) ///
    c.religion#(1.right_wing 1.left_wing 1.polit_orient_na 1.fem_resp 1.eq_hh_inc5 1.edu_cat_1 1.edu_cat_3) ///
    c.reciprocity#(1.right_wing 1.left_wing 1.polit_orient_na 1.fem_resp 1.eq_hh_inc5 1.edu_cat_1 1.edu_cat_3) ///
    c.tw_exp_share c.tw_exp_share#(1.right_wing 1.left_wing 1.polit_orient_na 1.fem_resp 1.eq_hh_inc5 1.edu_cat_1 1.edu_cat_3) ///
    $social_preferences $relig_community $social_contact 1.right_wing 1.left_wing 1.polit_orient_na if country_survey=="`country'", robust
    
    eststo `var'_`country'
    
        }
        }

    Now I want to illustrate the interaction effects of e.g. right wing and left wing with e.g. social mobility using coefplot and group the effects by countries. For this I used the following command:

    Code:
    coefplot (ideal_redis_DEU, keep(1.right_wing#c.soc_mob) msymbol(s) msize(small) pstyle(p1)) ///
    (ideal_redis_DEU, keep(1.left_wing#c.soc_mob) msymbol(t) msize(small) pstyle(p7)) ///
        ///
    (ideal_redis_GBR, keep(1.right_wing#c.soc_mob) msymbol(s) msize(small) pstyle(p1)) ///
    (ideal_redis_GBR, keep(1.left_wing#c.soc_mob) msymbol(t) msize(small) pstyle(p7)) ///
        ///
    (ideal_redis_ITA, keep(1.right_wing#c.soc_mob) msymbol(s) msize(small) pstyle(p1)) ///
    (ideal_redis_ITA, keep(1.left_wing#c.soc_mob) msymbol(t) msize(small) pstyle(p7)) ///
        ///
    (ideal_redis_JPN, keep(1.right_wing#c.soc_mob) msymbol(s) msize(small) pstyle(p1)) ///
    (ideal_redis_JPN, keep(1.left_wing#c.soc_mob) msymbol(t) msize(small) pstyle(p7)) ///
        ///
    (ideal_redis_SVN, keep(1.right_wing#c.soc_mob) msymbol(s) msize(small) pstyle(p1)) ///
    (ideal_redis_SVN, keep(1.left_wing#c.soc_mob) msymbol(t) msize(small) pstyle(p7)) ///
        ///
    (ideal_redis_USA, keep(1.right_wing#c.soc_mob) msymbol(s) msize(small) pstyle(p1)) ///
    (ideal_redis_USA, keep(1.left_wing#c.soc_mob) msymbol(t) msize(small) pstyle(p7)) ///
        ///
    ,  groups(1 2 = "Germany" 3 4 = "Great Britain" 5 6 = "Italy" 7 8 = "Japan" 9 10 = "Slovenia" 11 12 = "United States", angle(horizontal)) ///
        ///
    title("Desired redistribution", size(msmall)) nolabel xline(0, lcolor(gs6) lpattern(dash)) xmlabel(-2.5(1)2.5, nogrid) legend(order(2 "Right-wing" 4 "Left-Wing")) xlabel(, grid glcolor(gs14)) ytick(, nogrid) ylabel(, grid glcolor(gs14)) ///
    graphregion(color(white)) legend(size(vsmall) col(5) region(lwidth(vthin))) plotregion(lcolor(black) margin(vsmall) lwidth(vthin)) ///
    bgcolor(white) xsize(5.5) ///
    mlabel(cond(@pval<.001, "****", cond(@pval<.01, "***", cond(@pval<.05, "**", cond(@pval<.1,"*", "")))))

    Now, I would usually use a specification like:

    Code:
    groups(1.right_wing#c.soc_mob 1.left_wing#c.soc_mob= "Germany" ///
    However, my problem here is that the variables from the different models (for each country) all have the same name and therefore I don't know how to group interaction terms for e.g. Germany specifically. The graph as it currently looks like is attached as well.

    I hope my problem became clear and one can help me out here. Thanks in advance!








    Attached Files

  • #2
    Dear Statalist community,

    there are two things that I would like to change in my Coefplot command.

    1. I would like to order the interaction coefficients by countries, so that the order is: right-wing (country1), left-wing (country1), right-wing (country2), left-wing (country2) and so on. Right now Stata orders the coefficients by left-wing and right-wing automatically. I tried to solve this by including the order() option and the command now looks like this:

    Code:
    coefplot (ideal_redis_DEU, keep(1.right_wing#c.soc_mob) msymbol(s) msize(small) pstyle(p1)) ///
    (ideal_redis_DEU, keep(1.left_wing#c.soc_mob) msymbol(t) msize(small) pstyle(p7)) ///
        ///
    (ideal_redis_GBR, keep(1.right_wing#c.soc_mob) msymbol(s) msize(small) pstyle(p1)) ///
    (ideal_redis_GBR, keep(1.left_wing#c.soc_mob) msymbol(t) msize(small) pstyle(p7)) ///
        ///
    (ideal_redis_ITA, keep(1.right_wing#c.soc_mob) msymbol(s) msize(small) pstyle(p1)) ///
    (ideal_redis_ITA, keep(1.left_wing#c.soc_mob) msymbol(t) msize(small) pstyle(p7)) ///
        ///
    (ideal_redis_JPN, keep(1.right_wing#c.soc_mob) msymbol(s) msize(small) pstyle(p1)) ///
    (ideal_redis_JPN, keep(1.left_wing#c.soc_mob) msymbol(t) msize(small) pstyle(p7)) ///
        ///
    (ideal_redis_SVN, keep(1.right_wing#c.soc_mob) msymbol(s) msize(small) pstyle(p1)) ///
    (ideal_redis_SVN, keep(1.left_wing#c.soc_mob ) msymbol(t) msize(small) pstyle(p7)) ///
        ///
    (ideal_redis_USA, keep(1.right_wing#c.soc_mob) msymbol(s) msize(small) pstyle(p1)) ///
    (ideal_redis_USA, keep(1.left_wing#c.soc_mob) msymbol(t) msize(small) pstyle(p7)) ///
        ///
    , order(ideal_redis_DEU:1.right_wing#c.soc_mob ideal_redis_DEU:1.left_wing#c.soc_mob ideal_redis_GBR:1.right_wing#c.soc_mob ideal_redis_GBR:1.left_wing#c.soc_mob ///
     ideal_redis_ITA:1.right_wing#c.soc_mob ideal_redis_ITA:1.left_wing#c.soc_mob ideal_redis_JPN:1.right_wing#c.soc_mob ideal_redis_JPN:1.left_wing#c.soc_mob ///
     ideal_redis_SVN:1.right_wing#c.soc_mob ideal_redis_SVN:1.left_wing#c.soc_mob ideal_redis_USA:1.right_wing#c.soc_mob ideal_redis_USA:1.left_wing#c.soc_mob) ///
        ///
    groups(1 2 = "Germany" 3 4 = "Great Britain" 5 6 = "Italy" 7 8 = "Japan" 9 10 = "Slovenia" 11 12 = "United States", angle(horizontal)) ///
        ///
    title("Desired redistribution", size(msmall)) nolabel xline(0, lcolor(gs6) lpattern(dash)) xmlabel(-2.5(1)2.5, nogrid) legend(order(2 "Right-wing" 4 "Left-Wing")) xlabel(, grid glcolor(gs14)) ytick(, nogrid) ylabel(, grid glcolor(gs14)) ///
        graphregion(color(white)) legend(size(vsmall) col(5) region(lwidth(vthin))) plotregion(lcolor(black) margin(vsmall) lwidth(vthin)) bgcolor(white) xsize(5.5) ///
    mlabel(cond(@pval<.001, "****", cond(@pval<.01, "***", cond(@pval<.05, "**", cond(@pval<.1,"*", "")))))
    
    graph export Figures\Coefplot_ideal_redis_rw_lw_country.pdf, replace
    I tried to assign the coefficients to the equations (countries) as described in the help file.

    Code:
    , order(ideal_redis_DEU:1.right_wing#c.soc_mob ideal_redis_DEU:1.left_wing#c.soc_mob ideal_redis_GBR:1.right_wing#c.soc_mob ideal_redis_GBR:1.left_wing#c.soc_mob ///
     ideal_redis_ITA:1.right_wing#c.soc_mob ideal_redis_ITA:1.left_wing#c.soc_mob ideal_redis_JPN:1.right_wing#c.soc_mob ideal_redis_JPN:1.left_wing#c.soc_mob ///
     ideal_redis_SVN:1.right_wing#c.soc_mob ideal_redis_SVN:1.left_wing#c.soc_mob ideal_redis_USA:1.right_wing#c.soc_mob ideal_redis_USA:1.left_wing#c.soc_mob) ///
    However, the order of the coefficients in the graph doesn't change. Am I missing something here?

    2. After the coefficients are ordered by country, I would like to define group labels (e.g. Germany) for each pair of interaction coefficient. My problem here is, that the coefficients all have the same name (either 1.left-wing#c.soc.mob or 1.right-wing#c.soc.mob)
    and therefore I suggest the group() option cannot be applied like this. Maybe one has a suggestion on how to solve this?

    Thanks for your help.

    Comment


    • #3
      I did not attempt to run this because the code appears too elaborate. Can you trim it down to max 4 coefficients that reproduce the problem?

      Comment


      • #4
        Hi Andrew,


        here is an example from the dataset:

        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input float(ideal_redis soc_mob right_wing left_wing) byte(dummctry1 dummctry2 dummctry3 dummctry4) str5 country_survey
        12.100244  2.723296 0 1 1 0 0 0 "DEU"
         6.328649 3.8904226 0 0 1 0 0 0 "DEU"
        11.330771  1.556169 0 0 1 0 0 0 "DEU"
         7.114893  1.556169 0 0 1 0 0 0 "DEU"
        3.5471916   3.50138 1 0 1 0 0 0 "DEU"
          7.25711  1.556169 0 1 1 0 0 0 "DEU"
         6.222379 1.1671268 0 1 0 1 0 0 "GBR"
          1.63697  3.112338 1 0 0 1 0 0 "GBR"
         8.842057 2.3342535 1 0 0 1 0 0 "GBR"
         5.673986         0 0 0 0 1 0 0 "GBR"
         6.382203         0 0 0 0 1 0 0 "GBR"
        17.463827 1.1671268 1 0 0 1 0 0 "GBR"
           .35339  1.556169 0 0 0 1 0 0 "GBR"
        end
        label values soc_mob soc_mob
        label def soc_mob 0 "0 - There is not much opportunity", modify


        the shortened code of the regression for two countries is:

        Code:
        foreach country in DEU GBR {
            
        reg ideal_redis c.soc_mob#(1.right_wing 1.left_wing) if country_survey=="`country'", robust
        
        eststo ideal_redis_`country'
        
            }

        and the code for the graph would be this:

        Code:
        coefplot (ideal_redis_DEU, keep(1.right_wing#c.soc_mob) msymbol(s) msize(small) pstyle(p1)) ///
        (ideal_redis_DEU, keep(1.left_wing#c.soc_mob) msymbol(t) msize(small) pstyle(p7)) ///
            ///
        (ideal_redis_GBR, keep(1.right_wing#c.soc_mob) msymbol(s) msize(small) pstyle(p1)) ///
        (ideal_redis_GBR, keep(1.left_wing#c.soc_mob) msymbol(t) msize(small) pstyle(p7)) ///
            ///
        , order(ideal_redis_DEU:1.right_wing#c.soc_mob ideal_redis_DEU:1.left_wing#c.soc_mob ideal_redis_GBR:1.right_wing#c.soc_mob ideal_redis_GBR:1.left_wing#c.soc_mob) ///
            ///
        groups(1 2 = "Germany" 3 4 = "Great Britain", angle(horizontal)) ///
            ///
        title("Desired redistribution", size(msmall)) nolabel xline(0, lcolor(gs6) lpattern(dash)) xmlabel(-2.5(1)2.5, nogrid) legend(order(2 "Right-wing" 4 "Left-Wing")) xlabel(, grid glcolor(gs14)) ytick(, nogrid) ylabel(, grid glcolor(gs14)) ///
            graphregion(color(white)) legend(size(vsmall) col(5) region(lwidth(vthin))) plotregion(lcolor(black) margin(vsmall) lwidth(vthin)) bgcolor(white) xsize(5.5) ///
        mlabel(cond(@pval&lt;.001, "****", cond(@pval&lt;.01, "***", cond(@pval&lt;.05, "**", cond(@pval&lt;.1,"*", "")))))

        Thanks for your help!
        Attached Files

        Comment


        • #5
          Here is a start.

          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input float(ideal_redis soc_mob right_wing left_wing) byte(dummctry1 dummctry2 dummctry3 dummctry4) str5 country_survey
          12.100244  2.723296 0 1 1 0 0 0 "DEU"
           6.328649 3.8904226 0 0 1 0 0 0 "DEU"
          11.330771  1.556169 0 0 1 0 0 0 "DEU"
           7.114893  1.556169 0 0 1 0 0 0 "DEU"
          3.5471916   3.50138 1 0 1 0 0 0 "DEU"
            7.25711  1.556169 0 1 1 0 0 0 "DEU"
           6.222379 1.1671268 0 1 0 1 0 0 "GBR"
            1.63697  3.112338 1 0 0 1 0 0 "GBR"
           8.842057 2.3342535 1 0 0 1 0 0 "GBR"
           5.673986         0 0 0 0 1 0 0 "GBR"
           6.382203         0 0 0 0 1 0 0 "GBR"
          17.463827 1.1671268 1 0 0 1 0 0 "GBR"
             .35339  1.556169 0 0 0 1 0 0 "GBR"
          end
          label values soc_mob soc_mob
          label def soc_mob 0 "0 - There is not much opportunity", modify
          
          foreach country in DEU GBR {
              
              reg ideal_redis c.soc_mob#(1.right_wing 1.left_wing) if country_survey=="`country'", robust
              eststo ideal_redis_`country'
          }
          set scheme s1color
          coefplot (ideal_redis_DEU, keep(1.right_wing#c.soc_mob) msymbol(s) msize(small) pstyle(p1)) ///
          (ideal_redis_DEU, keep(1.left_wing#c.soc_mob) msymbol(t) msize(small) pstyle(p7)) ///
              ///
          (ideal_redis_GBR, keep(1.right_wing#c.soc_mob) msymbol(s) msize(small) pstyle(p1)) ///
          (ideal_redis_GBR, keep(1.left_wing#c.soc_mob) msymbol(t) msize(small) pstyle(p7)), ///
          aseq swapnames eqrename(ideal_redis_* = "" ) legend(order(2 "Right-wing" 4 "Left-Wing"))
          Res.:
          Click image for larger version

Name:	Graph.png
Views:	1
Size:	16.5 KB
ID:	1685106

          Comment


          • #6
            I adjusted the commands to my code and it worked really well, thanks! The graph now looks like attached. One thing I would like to change is the positioning of the coefficients as they are a bit offset. I tried using options ytick() and ylabel(), but it didn't work out yet. Do you have an idea how I can change the positions of the coefficents so that they are placed in the middle of the corresponding model (country)?


            the code for the current graph is:

            Code:
            coefplot (ideal_redis_DEU, keep(1.right_wing#c.soc_mob) msymbol(s) msize(small) pstyle(p1)) ///
            (ideal_redis_DEU, keep(1.left_wing#c.soc_mob) msymbol(t) msize(small) pstyle(p7)) ///
                ///
            (ideal_redis_GBR, keep(1.right_wing#c.soc_mob) msymbol(s) msize(small) pstyle(p1)) ///
            (ideal_redis_GBR, keep(1.left_wing#c.soc_mob) msymbol(t) msize(small) pstyle(p7)) ///
                ///
            (ideal_redis_ITA, keep(1.right_wing#c.soc_mob) msymbol(s) msize(small) pstyle(p1)) ///
            (ideal_redis_ITA, keep(1.left_wing#c.soc_mob) msymbol(t) msize(small) pstyle(p7)) ///
                ///
            (ideal_redis_JPN, keep(1.right_wing#c.soc_mob) msymbol(s) msize(small) pstyle(p1)) ///
            (ideal_redis_JPN, keep(1.left_wing#c.soc_mob) msymbol(t) msize(small) pstyle(p7)) ///
                ///
            (ideal_redis_SVN, keep(1.right_wing#c.soc_mob) msymbol(s) msize(small) pstyle(p1)) ///
            (ideal_redis_SVN, keep(1.left_wing#c.soc_mob) msymbol(t) msize(small) pstyle(p7)) ///
                ///
            (ideal_redis_USA, keep(1.right_wing#c.soc_mob) msymbol(s) msize(small) pstyle(p1)) ///
            (ideal_redis_USA, keep(1.left_wing#c.soc_mob) msymbol(t) msize(small) pstyle(p7)), bylabel(Interaction with social mobility) || ///
                ///
            (ideal_redis_DEU, keep(1.right_wing#c.immigr2) msymbol(s) msize(small) pstyle(p1)) ///
            (ideal_redis_DEU, keep(1.left_wing#c.immigr2) msymbol(t) msize(small) pstyle(p7)) ///
                ///
            (ideal_redis_GBR, keep(1.right_wing#c.immigr2) msymbol(s) msize(small) pstyle(p1)) ///
            (ideal_redis_GBR, keep(1.left_wing#c.immigr2) msymbol(t) msize(small) pstyle(p7)) ///
                ///
            (ideal_redis_ITA, keep(1.right_wing#c.immigr2) msymbol(s) msize(small) pstyle(p1)) ///
            (ideal_redis_ITA, keep(1.left_wing#c.immigr2) msymbol(t) msize(small) pstyle(p7)) ///
                ///
            (ideal_redis_JPN, keep(1.right_wing#c.immigr2) msymbol(s) msize(small) pstyle(p1)) ///
            (ideal_redis_JPN, keep(1.left_wing#c.immigr2) msymbol(t) msize(small) pstyle(p7)) ///
                ///
            (ideal_redis_SVN, keep(1.right_wing#c.immigr2) msymbol(s) msize(small) pstyle(p1)) ///
            (ideal_redis_SVN, keep(1.left_wing#c.immigr2) msymbol(t) msize(small) pstyle(p7)) ///
                ///
            (ideal_redis_USA, keep(1.right_wing#c.immigr2) msymbol(s) msize(small) pstyle(p1)) ///
            (ideal_redis_USA, keep(1.left_wing#c.immigr2) msymbol(t) msize(small) pstyle(p7)), bylabel(Interaction with immigrant perception) || ///    
                ///
            , aseq swapnames eqrename(ideal_redis_* = "" ) byopts(title("Marginal effects of political orientation by countries")) ///
            legend(order(2 "Right-wing" 4 "Left-Wing") size(vsmall) col(5) region(lwidth(vthin))) xline(0, lcolor(gs6) lpattern(dash)) ///
            xmlabel(-2.5(1)2.5, nogrid) xlabel(, grid glcolor(gs14)) ylabel(, grid glcolor(gs14)) ytick(, nogrid) graphregion(color(white)) ///
            subtitle(, size(medium)bcolor(white) lcolor(white)) plotregion(lcolor(black) margin(vsmall) lwidth(vthin)) bgcolor(white) xsize(5.5) ///
            mlabel(cond(@pval<.001, "****", cond(@pval<.01, "***", cond(@pval<.05, "**", cond(@pval<.1,"*", "")))))
            Attached Files

            Comment


            • #7
              Specify the offsets consistently (same values for right-wing and also same values for left-wing).

              Code:
              * Example generated by -dataex-. For more info, type help dataex
              clear
              input float(ideal_redis soc_mob right_wing left_wing) byte(dummctry1 dummctry2 dummctry3 dummctry4) str5 country_survey
              12.100244  2.723296 0 1 1 0 0 0 "DEU"
               6.328649 3.8904226 0 0 1 0 0 0 "DEU"
              11.330771  1.556169 0 0 1 0 0 0 "DEU"
               7.114893  1.556169 0 0 1 0 0 0 "DEU"
              3.5471916   3.50138 1 0 1 0 0 0 "DEU"
                7.25711  1.556169 0 1 1 0 0 0 "DEU"
               6.222379 1.1671268 0 1 0 1 0 0 "GBR"
                1.63697  3.112338 1 0 0 1 0 0 "GBR"
               8.842057 2.3342535 1 0 0 1 0 0 "GBR"
               5.673986         0 0 0 0 1 0 0 "GBR"
               6.382203         0 0 0 0 1 0 0 "GBR"
              17.463827 1.1671268 1 0 0 1 0 0 "GBR"
                 .35339  1.556169 0 0 0 1 0 0 "GBR"
              end
              label values soc_mob soc_mob
              label def soc_mob 0 "0 - There is not much opportunity", modify
              
              foreach country in DEU GBR {
                  
                  reg ideal_redis c.soc_mob#(1.right_wing 1.left_wing) if country_survey=="`country'", robust
                  eststo ideal_redis_`country'
              }
              set scheme s1color
              coefplot (ideal_redis_DEU, keep(1.right_wing#c.soc_mob) msymbol(s) msize(small) pstyle(p1) offset(-0.2) ) ///
              (ideal_redis_DEU, keep(1.left_wing#c.soc_mob) msymbol(t) msize(small) pstyle(p7) offset(0.2) ) ///
                  ///
              (ideal_redis_GBR, keep(1.right_wing#c.soc_mob) msymbol(s) msize(small) pstyle(p1) offset(-0.2)  ) ///
              (ideal_redis_GBR, keep(1.left_wing#c.soc_mob) msymbol(t) msize(small) pstyle(p7) offset(0.2)), ///
              aseq swapnames eqrename(ideal_redis_* = "" ) legend(order(2 "Right-wing" 4 "Left-Wing"))
              Click image for larger version

Name:	Graph.png
Views:	1
Size:	16.5 KB
ID:	1685159

              Comment


              • #8
                That worked perfectly, thanks!

                Comment


                • #9
                  Dear statalist experts,

                  I continued working on the regressions and now have another question regarding the coefplot command. In addition to the regression example from above I now run lincom tests to check whether differences between interactions of left-wing with social mobility and right-wing with social mobility are significant.

                  The code of the example regression therefore is:

                  Code:
                  foreach country in DEU GBR ITA JPN SVN USA {
                      
                  reg ideal_redis c.soc_mob#(1.right_wing 1.left_wing) if country_survey=="`country'", robust
                  
                  eststo ideal_redis_`country'
                  
                  lincom 1.right_wing#c.soc_mob - 1.left_wing#c.soc_mob
                      local ir_lc2_`country'_b=`r(estimate)'
                      local ir_lc2_`country'_se=`r(se)'
                      local ir_lc2_`country'_p=`r(p)'
                  
                  }
                  Now I wondered, whether it's possible to display the p-values of the lincom tests for each pair of interaction coefficients in the coefplot (maybe at the upper bound of the confidence intervals). From the help file I took that p-values from the regression can be displayed by using the mlabel(@pval) command, but I didn't figure out yet how to display the p-values from separate lincom tests.

                  Thanks again for your help, really appreciate it.

                  Comment


                  • #10
                    I would start a new thread with an appropriate title and accompanying data example as you are no longer grouping coefficients.

                    Comment


                    • #11
                      I started a new thread for this topic, here is the link to it: https://www.statalist.org/forums/for...ls-in-coefplot

                      Comment

                      Working...
                      X