Announcement

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

  • How to graph the aggregate marginal means of several variables in one figure?

    Hi everyone,

    I would like to display the marginal means of many variables in one figure, but I don't know how best to do this. Does it make sense to simply display all variables and their values next to each other on the x-axis and if so, what would the corresponding code be?

    This is the random intercept regression model I'm running:

    Code:
    xtreg fs_wage b0.p_sex13 b0.p_att b0.p_ethname13 b0.p_occstat34 b0.p_earnlevels34 b0.p_workperf34 if int_flag_wage2==0 & int_flag_survey_dur1_34==0, re vce(cluster respid) 
    
    margins
    This is the data I'm using:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte fs_wage long(p_sex13 p_att p_ethname13) byte p_occstat34 double p_earnlevels34 byte p_workperf34 float(int_flag_wage2 int_flag_survey_dur1_34)
    -5 1 2 1 1 0 0 0 0
    -5 0 2 1 0 0 2 0 0
    -5 0 2 0 2 0 0 0 0
    -5 0 1 1 0 0 0 0 0
    -5 0 1 0 2 0 0 0 0
    -5 0 2 1 0 0 0 0 0
    -5 1 2 0 0 0 0 0 0
    -5 0 2 0 0 0 0 0 0
    -5 0 2 0 0 0 0 0 0
    -5 1 1 1 0 0 0 0 0
    -5 1 2 0 1 0 3 0 0
    -5 1 2 2 2 0 1 0 0
    -5 1 0 2 0 0 0 0 0
    -5 1 0 2 0 0 0 0 0
    -5 0 0 2 1 0 3 0 0
    -5 1 2 2 0 0 2 0 0
    -5 0 0 1 0 0 0 0 0
    -5 0 2 1 0 0 2 0 0
    -5 1 0 0 1 0 3 0 0
    -5 1 0 0 0 0 3 0 0
    -5 . 1 . 0 0 0 0 0
    -5 1 1 0 0 0 2 0 0
    -5 0 1 2 0 0 0 0 0
    -5 1 2 2 0 0 0 0 0
    -5 0 2 2 0 0 2 0 0
    -5 0 2 2 0 0 2 0 0
    -5 1 0 1 0 0 3 0 0
    -5 1 2 1 2 0 1 0 0
    -5 0 0 0 1 0 3 0 0
    -5 0 0 2 0 0 3 0 0
    -5 0 0 1 0 0 3 0 0
    -5 0 1 2 0 0 0 0 0
    -5 1 2 0 0 0 1 0 0
    -5 1 2 2 0 0 3 0 0
    -5 . 2 . 0 0 0 0 0
    -5 1 2 2 0 0 0 0 0
    -5 0 1 2 0 0 2 0 0
    -5 0 2 0 1 0 3 0 0
    -5 0 2 2 0 0 0 0 0
    -5 1 2 2 0 0 3 0 0
    -5 1 1 0 0 0 0 0 0
    -5 0 1 1 2 0 2 0 0
    -5 0 0 1 2 0 1 0 0
    -5 0 1 0 0 0 3 0 0
    -5 1 2 1 0 0 0 0 0
    -5 0 2 1 0 0 0 0 0
    -5 0 0 0 1 0 2 0 0
    -5 1 1 2 0 0 1 0 0
    -5 . 1 . 2 0 2 0 0
    -5 0 1 2 1 0 0 0 0
    -5 1 1 0 0 0 3 0 0
    -5 0 2 0 0 0 1 0 0
    -5 1 2 1 2 0 1 0 0
    -5 0 2 1 0 0 3 0 0
    -5 1 1 0 0 0 3 0 0
    -5 1 0 1 0 0 2 0 0
    -5 0 0 1 0 0 3 0 0
    -5 0 1 0 0 0 0 0 0
    -5 0 0 1 0 0 0 0 0
    -5 0 2 0 0 0 3 0 0
    -5 1 2 0 0 0 0 0 0
    -5 1 1 2 2 0 2 0 0
    -5 0 0 0 1 0 0 0 0
    -5 1 2 1 0 0 0 0 0
    -5 . 1 . 0 0 2 0 0
    -5 0 1 2 0 0 0 0 0
    -5 . 2 . 2 0 0 0 0
    -5 0 0 0 0 0 0 0 0
    -5 . 1 . 2 0 2 0 0
    -5 0 0 0 0 0 2 0 0
    -5 0 2 2 0 0 2 0 0
    -5 0 2 1 0 0 0 0 0
    -5 1 2 1 1 0 0 0 0
    -5 0 2 0 2 0 0 0 0
    -5 1 2 1 0 0 0 0 0
    -5 1 0 2 2 0 0 0 0
    -5 . 2 . 2 0 2 0 0
    -5 0 1 2 0 0 0 0 0
    -5 1 2 0 1 0 3 0 0
    -5 1 0 0 0 0 0 0 0
    -5 0 2 2 1 0 0 0 0
    -5 0 0 2 0 0 3 0 0
    -5 1 2 1 1 0 0 0 0
    -5 1 0 0 0 0 3 0 0
    -5 . 0 . 0 0 0 0 0
    -5 0 2 1 0 0 1 0 0
    -5 0 2 0 1 0 1 0 0
    -5 1 1 0 0 0 0 0 0
    -5 0 2 0 0 0 0 0 0
    -5 0 1 0 0 0 0 0 0
    -5 . 2 . 2 0 0 0 0
    -5 0 2 0 0 0 0 0 0
    -5 0 0 2 2 0 3 0 0
    -5 0 2 0 0 0 0 0 0
    -5 1 1 2 0 0 3 0 0
    -5 1 1 1 2 0 1 0 0
    -5 1 0 2 2 0 0 0 0
    -5 1 2 0 0 0 2 0 0
    -5 1 0 1 0 0 2 0 0
    -5 0 0 0 0 0 0 0 0
    end
    label values fs_wage labels125
    label values p_sex13 p_sex13
    label def p_sex13 0 "0. female", modify
    label def p_sex13 1 "1. male", modify
    label values p_att p_att
    label def p_att 0 "0. low", modify
    label def p_att 1 "1. average", modify
    label def p_att 2 "2. high", modify
    label values p_ethname13 a_name
    label def a_name 0 "0. German Name", modify
    label def a_name 1 "1. Greek Name", modify
    label def a_name 2 "2. Turkish Name", modify
    label values p_occstat34 a_occstat2
    label def a_occstat2 0 "0. Low status", modify
    label def a_occstat2 1 "1. Medium status", modify
    label def a_occstat2 2 "2. High status", modify
    label values p_earnlevels34 p_earnlevels34
    label def p_earnlevels34 0 "0. low", modify
    label values p_workperf34 p_workperf34
    label def p_workperf34 0 "0. No information provided", modify
    label def p_workperf34 1 "1. Low performance", modify
    label def p_workperf34 2 "2. Medium performance", modify
    label def p_workperf34 3 "3. High performance", modify

  • #2
    Hi again,

    I'm very sorry I forgot to mention that I set panel data and that the respondent ID Variable is needed for that. So here is the code and the correct data example:

    Code:
    * Random intercept regression model 
    xtset respid
    xtreg fs_wage b0.p_sex13 b0.p_att b0.p_ethname13 b0.p_occstat34 b0.p_earnlevels34 b0.p_workperf34 if int_flag_wage2==0 & int_flag_survey_dur1_34==0, re vce(cluster respid)
    *

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte fs_wage long(p_sex13 p_att p_ethname13) byte p_occstat34 double p_earnlevels34 byte p_workperf34 float(int_flag_wage2 int_flag_survey_dur1_34) long respid
    -5 1 2 1 1 0 0 0 0 28366
    -5 0 2 1 0 0 2 0 0 18693
    -5 0 2 0 2 0 0 0 0 34920
    -5 0 1 1 0 0 0 0 0 26267
    -5 0 1 0 2 0 0 0 0 34871
    -5 0 2 1 0 0 0 0 0 26653
    -5 1 2 0 0 0 0 0 0 32264
    -5 0 2 0 0 0 0 0 0 26960
    -5 0 2 0 0 0 0 0 0 32481
    -5 1 1 1 0 0 0 0 0 20785
    -5 1 2 0 1 0 3 0 0 24039
    -5 1 2 2 2 0 1 0 0 31278
    -5 1 0 2 0 0 0 0 0 25979
    -5 1 0 2 0 0 0 0 0 29317
    -5 0 0 2 1 0 3 0 0 25162
    -5 1 2 2 0 0 2 0 0 18409
    -5 0 0 1 0 0 0 0 0 25679
    -5 0 2 1 0 0 2 0 0 20223
    -5 1 0 0 1 0 3 0 0 24865
    -5 1 0 0 0 0 3 0 0 33827
    -5 . 1 . 0 0 0 0 0 19114
    -5 1 1 0 0 0 2 0 0 28343
    -5 0 1 2 0 0 0 0 0 26118
    -5 1 2 2 0 0 0 0 0 21397
    -5 0 2 2 0 0 2 0 0 24523
    -5 0 2 2 0 0 2 0 0 29580
    -5 1 0 1 0 0 3 0 0 35751
    -5 1 2 1 2 0 1 0 0 18135
    -5 0 0 0 1 0 3 0 0 26746
    -5 0 0 2 0 0 3 0 0 35150
    -5 0 0 1 0 0 3 0 0 20659
    -5 0 1 2 0 0 0 0 0 19114
    -5 1 2 0 0 0 1 0 0 26695
    -5 1 2 2 0 0 3 0 0 22632
    -5 . 2 . 0 0 0 0 0 29873
    -5 1 2 2 0 0 0 0 0 33564
    -5 0 1 2 0 0 2 0 0 18118
    -5 0 2 0 1 0 3 0 0 26715
    -5 0 2 2 0 0 0 0 0 32481
    -5 1 2 2 0 0 3 0 0 31786
    -5 1 1 0 0 0 0 0 0 31935
    -5 0 1 1 2 0 2 0 0 31702
    -5 0 0 1 2 0 1 0 0 25684
    -5 0 1 0 0 0 3 0 0 30547
    -5 1 2 1 0 0 0 0 0 30921
    -5 0 2 1 0 0 0 0 0 34916
    -5 0 0 0 1 0 2 0 0 26557
    -5 1 1 2 0 0 1 0 0 31350
    -5 . 1 . 2 0 2 0 0 31022
    -5 0 1 2 1 0 0 0 0 28186
    -5 1 1 0 0 0 3 0 0 33875
    -5 0 2 0 0 0 1 0 0 35111
    -5 1 2 1 2 0 1 0 0 30003
    -5 0 2 1 0 0 3 0 0 30983
    -5 1 1 0 0 0 3 0 0 34916
    -5 1 0 1 0 0 2 0 0 27699
    -5 0 0 1 0 0 3 0 0 25797
    -5 0 1 0 0 0 0 0 0 21753
    -5 0 0 1 0 0 0 0 0 30594
    -5 0 2 0 0 0 3 0 0 25979
    -5 1 2 0 0 0 0 0 0 19215
    -5 1 1 2 2 0 2 0 0 20527
    -5 0 0 0 1 0 0 0 0 24013
    -5 1 2 1 0 0 0 0 0 25794
    -5 . 1 . 0 0 2 0 0 23749
    -5 0 1 2 0 0 0 0 0 36214
    -5 . 2 . 2 0 0 0 0 28830
    -5 0 0 0 0 0 0 0 0 25911
    -5 . 1 . 2 0 2 0 0 18396
    -5 0 0 0 0 0 2 0 0 33617
    -5 0 2 2 0 0 2 0 0 25785
    -5 0 2 1 0 0 0 0 0 25822
    -5 1 2 1 1 0 0 0 0 34233
    -5 0 2 0 2 0 0 0 0 27288
    -5 1 2 1 0 0 0 0 0 26960
    -5 1 0 2 2 0 0 0 0 20409
    -5 . 2 . 2 0 2 0 0 28187
    -5 0 1 2 0 0 0 0 0 32165
    -5 1 2 0 1 0 3 0 0 20409
    -5 1 0 0 0 0 0 0 0 25678
    -5 0 2 2 1 0 0 0 0 28233
    -5 0 0 2 0 0 3 0 0 24954
    -5 1 2 1 1 0 0 0 0 33115
    -5 1 0 0 0 0 3 0 0 29443
    -5 . 0 . 0 0 0 0 0 23303
    -5 0 2 1 0 0 1 0 0 25379
    -5 0 2 0 1 0 1 0 0 20684
    -5 1 1 0 0 0 0 0 0 35511
    -5 0 2 0 0 0 0 0 0 27053
    -5 0 1 0 0 0 0 0 0 34670
    -5 . 2 . 2 0 0 0 0 26880
    -5 0 2 0 0 0 0 0 0 30921
    -5 0 0 2 2 0 3 0 0 25655
    -5 0 2 0 0 0 0 0 0 22928
    -5 1 1 2 0 0 3 0 0 22932
    -5 1 1 1 2 0 1 0 0 25541
    -5 1 0 2 2 0 0 0 0 21851
    -5 1 2 0 0 0 2 0 0 32165
    -5 1 0 1 0 0 2 0 0 31028
    -5 0 0 0 0 0 0 0 0 29790
    end
    label values fs_wage labels125
    label values p_sex13 p_sex13
    label def p_sex13 0 "0. female", modify
    label def p_sex13 1 "1. male", modify
    label values p_att p_att
    label def p_att 0 "0. low", modify
    label def p_att 1 "1. average", modify
    label def p_att 2 "2. high", modify
    label values p_ethname13 a_name
    label def a_name 0 "0. German Name", modify
    label def a_name 1 "1. Greek Name", modify
    label def a_name 2 "2. Turkish Name", modify
    label values p_occstat34 a_occstat2
    label def a_occstat2 0 "0. Low status", modify
    label def a_occstat2 1 "1. Medium status", modify
    label def a_occstat2 2 "2. High status", modify
    label values p_earnlevels34 p_earnlevels34
    label def p_earnlevels34 0 "0. low", modify
    label values p_workperf34 p_workperf34
    label def p_workperf34 0 "0. No information provided", modify
    label def p_workperf34 1 "1. Low performance", modify
    label def p_workperf34 2 "2. Medium performance", modify
    label def p_workperf34 3 "3. High performance", modify

    Comment


    • #3
      I am not clear on what this is asking, but consider

      Code:
      . search designplot, sj
      
      Search of official help files, FAQs, Examples, and Stata Journals
      
      SJ-19-3 gr0061_3  . . . . . . . . . . . . . . . Software update for designplot
              (help designplot if installed)  . . . . . . . . . . . . . .  N. J. Cox
              Q3/19   SJ 19(3):748--751
              any attempt to use the missing option of graph dot,
              graph hbar, or graph bar is now ignored and advice on
              what to do instead is shown
      
      SJ-17-3 gr0061_2  . . . . . . . . . . . . . . . Software update for designplot
              (help designplot if installed)  . . . . . . . . . . . . . .  N. J. Cox
              Q3/17   SJ 17(3):779
              help file updated
      
      SJ-15-2 gr0061_1  . . . . . . . . . . . . . . . Software update for designplot
              (help designplot if installed)  . . . . . . . . . . . . . .  N. J. Cox
              Q2/15   SJ 15(2):605--606
              bug fixed for Stata 14
      
      SJ-14-4 gr0061  Design plots for graphical summary of a response given factors
              (help designplot if installed)  . . . . . . . . . . . . . .  N. J. Cox
              Q4/14   SJ 14(4):975--990
              produces a graphical summary of a numeric response variable
              given one or more factors

      Comment


      • #4
        Hi Nick, thanks a lot for your answer and I'm very sorry that I was not able to express my question clearly.

        My dependent variable are fairness judgments of wages on a scale from -5 "unfairly low" to 5 "unfairly high". It's data from a factorial survey experiment, therefore I created one regression table including all treatments that varied.

        I was asked to calculate and graph the aggregate marginal means so that I can better compare fairness evaluations across all of the treatments. I already created a table including the marginal means (see below), however now I'm struggling with how to graph those results. My idea for the plot was to arrange all variables and their levels along the x-axis and draw the marginal means above of it, similar to a scatterplot. But neither I'm sure whether this makes sense nor do I know how to code this.

        Table 6: Marginal means from the random intercept regression model of fairness evaluations
        (1) (2) (3)
        Main effects model: all VPs Main effects model: female VPs Main effects model: male VPs
        margin se margin se margin se
        Vignette Dimensions
        Gender
        Female -0.463 0.021
        Male -0.473 0.021
        Attractiveness
        Low -0.942 0.023 -0.428 0.028 -0.574 0.029
        Average -0.446 0.022 -0.479 0.027 -0.383 0.028
        High -0.465 0.023 -0.474 0.029 -0.475 0.029
        Name
        German -0.439 0.021 -0.443 0.025 -0.443 0.026
        Greek -0.497 0.024 -0.508 0.030 -0.495 0.030
        Turkish -0.481 0.024 -0.439 0.030 -0.509 0.030
        Occupational status
        Low status -1.586 0.027 -0.575 0.032 -1.602 0.033
        Medium status 0.302 0.023 0.323 0.028 0.267 0.027
        High status -0.127 0.024 -0.110 0.029 -0.128 0.029
        Earnings
        Low -1.435 0.024 -1.439 0.029 -1.435 0.029
        Average -0.411 0.023 -0.414 0.027 -0.414 0.028
        High 0.437 0.024 0.433 0.029 0.448 0.029
        Work performance
        No information provided -0.582 0.021 -0.563 0.025 -0.606 0.024
        Low performance 0.392 0.033 0.444 0.041 0.319 0.043
        Medium performance -0.431 0.028 -0.484 0.036 -0.359 0.037
        High performance -1.030 0.028 -1.043 0.035 -1.009 0.037

        Comment

        Working...
        X