Announcement

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

  • line graph of row percentage by different groups

    Hi Statalist,

    I am trying to generate a line graph. I am using four variables. My outcome, which would go on the y axis, is binary for whether an individual is employed or not. The x axis variable is the total number of siblings. I am trying to graph the percentage of individuals employed at every value of number of children by four groups: mother (of individual) employed, mother unemployed, father employed, father unemployed.

    My outcome y axis variable is cremp2, my x axis variable is totalsib and the two variables for the groups are mtempst and ftempst.

    I have tried following the advice in this post: https://www.statalist.org/forums/for...alues-by-group ; but without success.


    Please see below an example of my dataset

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte cremp2 float totalsib byte(ftempst mtempst) int round
    0  3 1 0 2012
    0  2 1 0 2018
    0  6 1 0 2012
    0  7 1 0 2018
    1  3 1 0 2012
    1  4 0 0 2018
    0  3 1 0 2012
    0  3 0 0 2018
    0  1 1 1 2012
    0  2 1 0 2018
    0  6 1 0 2012
    0  6 1 0 2018
    1  3 1 0 2012
    0  3 1 0 2018
    0  3 1 0 2012
    0  3 1 1 2018
    0  4 1 0 2012
    0  5 1 0 2018
    0  5 1 0 2012
    0  4 1 0 2018
    0  6 1 0 2012
    0  3 1 0 2018
    0  3 1 0 2012
    0  2 1 0 2018
    0  5 1 0 2012
    0  7 1 0 2018
    0  5 1 0 2012
    0  4 1 0 2018
    0  5 1 0 2012
    1  1 0 1 2018
    0  5 1 0 2012
    0  5 1 0 2018
    1  2 1 1 2012
    1  2 1 0 2018
    0  5 1 0 2012
    0  5 1 0 2018
    0  8 1 0 2012
    1  7 1 0 2018
    0  5 1 0 2012
    0  4 1 0 2018
    0  5 1 1 2012
    0  5 1 1 2018
    0  3 1 1 2012
    0  3 1 1 2018
    0  2 1 0 2012
    0  2 1 0 2018
    0 11 1 0 2012
    0 12 1 0 2018
    0  5 1 0 2012
    1  5 1 0 2018
    1  3 1 1 2012
    0  3 1 0 2018
    0  3 1 0 2012
    1  3 1 0 2018
    0  5 1 1 2012
    0  5 1 0 2018
    0  4 1 0 2012
    1  4 1 0 2018
    0  6 1 0 2012
    0  7 1 0 2018
    0  3 1 0 2012
    1  3 1 0 2018
    0  5 1 0 2012
    0  5 1 0 2018
    0  6 1 0 2012
    0  5 1 0 2018
    1  5 1 0 2012
    1  5 1 0 2018
    0  4 1 0 2012
    1  4 1 0 2018
    0  5 1 0 2012
    0  5 0 0 2018
    0  2 1 0 2012
    0  2 0 0 2018
    0  3 1 0 2012
    0  4 1 0 2018
    0  3 1 0 2012
    0  4 1 0 2018
    0  5 1 0 2012
    0  6 1 0 2018
    0  3 1 0 2012
    0  5 1 0 2018
    0  5 1 0 2012
    0  5 1 0 2018
    0  6 1 0 2012
    0  6 1 0 2018
    0  5 1 0 2012
    0  5 1 0 2018
    0  5 1 0 2012
    0  5 1 0 2018
    0  4 1 1 2012
    0  4 1 1 2018
    1  2 1 1 2012
    1  2 1 0 2018
    1  2 1 0 2012
    1  1 1 0 2018
    0  4 1 0 2012
    0  4 0 0 2018
    0  7 1 0 2012
    0  7 1 0 2018
    end
    label values cremp2 emp
    label def emp 0 "No", modify
    label def emp 1 "Yes", modify
    label values ftempst femp
    label def femp 0 "Unemployed", modify
    label def femp 1 "Employed", modify
    label values mtempst memp
    label def memp 0 "Unemployed", modify
    label def memp 1 "Employed", modify

    EDIT:

    I have made some progress with the following code:

    Code:
    egen crempmean = mean(cremp2), by(totalsib ftempst)
    egen crmean = mean(100 * cremp2), by(totalsib ftempst)
    twoway connected crmean totalsib , sort by(ftempst) saving (g1)
     
    egen crempmean1 = mean(cremp2), by(totalsib mtempst)
    egen crmean1 = mean(100 * cremp2), by(totalsib mtempst)
    twoway connected crmean1 totalsib , sort by(mtempst) saving (g2)
    
    gr combine g1.gph g2.gph
    Which produces this graph - but is there anyone to get them all onto one graph?
    Click image for larger version

Name:	Graph12.png
Views:	1
Size:	48.5 KB
ID:	1559707

    Last edited by Sherine Maui; 19 Jun 2020, 10:01.

  • #2
    Your variables ftempst mtempst jointly define four categories, 0 0, 1 0, 0 1 and 1 1. That being so, those variables cut across each other and I can't see a way to combine the graphs. without sacrificing something.

    Comment


    • #3
      I see what you mean Nick, thanks. I'll keep them as separate graphs then.

      Comment


      • #4
        You could go for a composite. Here's the whole code I tried, starting with your data example. Presumably the graphs are more interesting for your full dataset.

        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input byte cremp2 float totalsib byte(ftempst mtempst) int round
        0  3 1 0 2012
        0  2 1 0 2018
        0  6 1 0 2012
        0  7 1 0 2018
        1  3 1 0 2012
        1  4 0 0 2018
        0  3 1 0 2012
        0  3 0 0 2018
        0  1 1 1 2012
        0  2 1 0 2018
        0  6 1 0 2012
        0  6 1 0 2018
        1  3 1 0 2012
        0  3 1 0 2018
        0  3 1 0 2012
        0  3 1 1 2018
        0  4 1 0 2012
        0  5 1 0 2018
        0  5 1 0 2012
        0  4 1 0 2018
        0  6 1 0 2012
        0  3 1 0 2018
        0  3 1 0 2012
        0  2 1 0 2018
        0  5 1 0 2012
        0  7 1 0 2018
        0  5 1 0 2012
        0  4 1 0 2018
        0  5 1 0 2012
        1  1 0 1 2018
        0  5 1 0 2012
        0  5 1 0 2018
        1  2 1 1 2012
        1  2 1 0 2018
        0  5 1 0 2012
        0  5 1 0 2018
        0  8 1 0 2012
        1  7 1 0 2018
        0  5 1 0 2012
        0  4 1 0 2018
        0  5 1 1 2012
        0  5 1 1 2018
        0  3 1 1 2012
        0  3 1 1 2018
        0  2 1 0 2012
        0  2 1 0 2018
        0 11 1 0 2012
        0 12 1 0 2018
        0  5 1 0 2012
        1  5 1 0 2018
        1  3 1 1 2012
        0  3 1 0 2018
        0  3 1 0 2012
        1  3 1 0 2018
        0  5 1 1 2012
        0  5 1 0 2018
        0  4 1 0 2012
        1  4 1 0 2018
        0  6 1 0 2012
        0  7 1 0 2018
        0  3 1 0 2012
        1  3 1 0 2018
        0  5 1 0 2012
        0  5 1 0 2018
        0  6 1 0 2012
        0  5 1 0 2018
        1  5 1 0 2012
        1  5 1 0 2018
        0  4 1 0 2012
        1  4 1 0 2018
        0  5 1 0 2012
        0  5 0 0 2018
        0  2 1 0 2012
        0  2 0 0 2018
        0  3 1 0 2012
        0  4 1 0 2018
        0  3 1 0 2012
        0  4 1 0 2018
        0  5 1 0 2012
        0  6 1 0 2018
        0  3 1 0 2012
        0  5 1 0 2018
        0  5 1 0 2012
        0  5 1 0 2018
        0  6 1 0 2012
        0  6 1 0 2018
        0  5 1 0 2012
        0  5 1 0 2018
        0  5 1 0 2012
        0  5 1 0 2018
        0  4 1 1 2012
        0  4 1 1 2018
        1  2 1 1 2012
        1  2 1 0 2018
        1  2 1 0 2012
        1  1 1 0 2018
        0  4 1 0 2012
        0  4 0 0 2018
        0  7 1 0 2012
        0  7 1 0 2018
        end
        label values cremp2 emp
        label def emp 0 "No", modify
        label def emp 1 "Yes", modify
        label values ftempst femp
        label def femp 0 "Unemployed", modify
        label def femp 1 "Employed", modify
        label values mtempst memp
        label def memp 0 "Unemployed", modify
        label def memp 1 "Employed", modify
        
        * NJC starts here
        
        gen group = mtempst + 2 * ftempst
        label def group 0 neither 1 father 2 mother 3 both
        label val group group
        
        egen mean = mean(cremp2), by(totalsib group)
        separate mean, by(group) veryshortlabel
        
        twoway connected mean? totalsib , sort scheme(s1color) ms(Oh Dh Th Sh) mc(black blue magenta red) lc(black blue magenta red) legend(col(1) pos(1) ring(0)) xla(1/12) name(G1)
        
        twoway connected mean? totalsib, by(group, legend(off) note("")) sort scheme(s1color) ms(Oh Dh Th Sh) mc(black blue magenta red) lc(black blue magenta red) xla(1/12) name(G2)
        Click image for larger version

Name:	maui_g1.png
Views:	1
Size:	33.8 KB
ID:	1559795

        Click image for larger version

Name:	maui_g2.png
Views:	1
Size:	25.4 KB
ID:	1559796


        EDIT: I think I have "father" and "mother" wrong way round here, but hope the principle is clear.
        Last edited by Nick Cox; 20 Jun 2020, 03:21.

        Comment


        • #5
          Thank you Nick, these graphs are what I was trying to produce and they are indeed more informative using my full sample.

          Comment

          Working...
          X