Announcement

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

  • Plotting percentage of variables

    Hello,

    I have two variables and two groups in my data that I want to plot the percentages of. So, I have kids who are either "screened in" or "screened out" measured by a 0 1 dummy called "screenedin." I also have two variables: exp_risk_screenout and exp_risk_screenin. These are also dummy variables that show, for instance, you are exposed to risk and also screened in you will get a 1 for exp_risk_screenin. I want to plot these variables together so that it would show two bars, one for screened in and one for screened out and it would show the percentages like 27% have a 1 for exp_risk_screenout and 10% have a 1 for exp_risk_screenout. I have put data below. Thanks -CJ

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(screenedin exp_risk_screenout)
    0 0
    0 0
    0 0
    0 0
    0 0
    1 0
    1 0
    1 0
    1 0
    1 0
    1 0
    1 0
    1 0
    1 0
    1 0
    0 0
    0 0
    0 0
    0 0
    0 0
    1 0
    0 0
    0 0
    0 0
    0 0
    0 0
    0 0
    0 1
    1 0
    0 1
    1 0
    1 0
    0 0
    1 0
    0 0
    1 0
    1 0
    0 0
    0 0
    0 0
    0 0
    0 0
    1 0
    0 1
    0 0
    1 0
    1 0
    0 0
    1 0
    1 0
    1 0
    0 1
    1 0
    1 0
    1 0
    1 0
    0 0
    1 0
    1 0
    1 0
    1 0
    1 0
    1 0
    0 1
    0 0
    0 0
    0 0
    0 0
    0 1
    0 0
    1 0
    1 0
    0 0
    0 0
    1 0
    1 0
    1 0
    1 0
    1 0
    1 0
    1 0
    1 0
    0 0
    0 1
    1 0
    0 0
    1 0
    0 0
    1 0
    1 0
    0 0
    0 0
    0 0
    1 0
    1 0
    1 0
    1 0
    0 0
    1 0
    1 0
    end

  • #2
    The data example shows two variables whereas you refer to four. Also, the example seems jumbled

    27% have a 1 for exp_risk_screenout and 10% have a 1 for exp_risk_screenout.
    To move forward, let's fake a dataset with 4 binary indicator variables with values (0, 1), two which are notionally outcomes and two notionally controls. Then it's elementary but fundamental that

    mean of binary outcome == proportion of outcomes that are 1

    and showing percents instead of proportions is just cosmetic.

    [CODE}
    * fake dataset
    clear
    set obs 100
    set seed 2803
    gen X1 = runiform() < 0.7
    gen X2 = runiform() > 0.6
    gen Y1 = runiform() > 0.5
    gen Y2 = runiform() > 0.4

    * graph bar defaults to showing means
    graph bar Y1 Y2, over(X1)

    graph bar Y1 Y2, over(X1) over(X2)
    [/CODE]


    To see percents instead, use something like
    Code:
    yla(0 0.25 "25" 0.5 "50" 0.75 "75" 1 "100") ytitle(% of whatever)
    as extra options,

    To swap the order of the bars,use statplot from SSC; statplot is a good search term to find discussions here.

    If that is not what you want, please come back with more precise information.
    Last edited by Nick Cox; 10 Aug 2022, 13:54.

    Comment

    Working...
    X