Announcement

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

  • ByHist - to create a histogram

    I would like to plot a histogram using weights. Just like Ariels' paper here.
    Graphical displays for assessing covariate balance in matching studies (lindenconsulting.org)
    He actually recommends using 'byhist' written by Austin.

    I've got category variables which I would like to show the change on two separate graphs (pre-matching) - pre propensity scores matching, and post -matching.
    I expect with the post-matching for both treatment (smoking status Y/N) to be equal to each other.
    After matching, a frequency weight is generated _weight. I used 'BYHIST' due to Ariels' paper.

    The stata command, does not take non-integer weights, so I created integers by *10 - as seen in variable precision3 and intp.

    The problem is the x-axis scale, is 0 , 0.2, .4,.6,.8,1. When actually these are binary categorical variables (0 / 1) . How can I change the axis?
    I tried using the graph editor --> Axis >min -max --> However the axis then changes to 0.03 and 0.9 (picture below).
    Do you know how I can just bring the bins close to each other? - as seen in my attempted pen drawing (showing yellow arrow to bring together), green text: 0 / 1 on x axis for gender categorical variable.
    PS. These are post matching so as you can see they are pretty equal.

    Click image for larger version

Name:	Capture2.PNG
Views:	1
Size:	36.3 KB
ID:	1705611


    Code:
    gen precision3= _weight*10
    gen intp = int(precision3)
    byhist gender [fw=intp], by(smoking) name(graph2)
    Histogram produced:


    Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	21.8 KB
ID:	1705609




    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(gender smoking infection socialdeprivation ethnicity) double _pscore byte(_treated _support) double(_weight _infection) byte(_id _n1 _n2 _n3) float _nn double _pdif float(precision3 intp)
    0 1 1 1 1  .8866625742391517 1 0                  .                 . 19 .  . . .                    .         .  .
    0 1 1 1 1  .8866625742391517 1 0                  .                 . 18 .  . . .                    .         .  .
    0 1 0 . 4                  . . .                  .                 . 22 .  . . .                    .         .  .
    0 1 1 1 3  .9372933094185172 1 0                  .                 . 20 .  . . .                    .         .  .
    0 1 1 1 4  .9538339376992043 1 0                  .                 . 21 .  . . .                    .         .  .
    1 0 1 4 1 .27681680297995453 0 1  .3333333333333333                 .  4 .  . . 0                    .  3.333333  3
    0 0 0 7 1 .18353598336623161 0 1  .3333333333333333                 .  2 .  . . 0                    .  3.333333  3
    0 0 0 6 2  .3595669083790513 0 1  .3333333333333333                 .  6 .  . . 0                    .  3.333333  3
    1 0 0 7 4 .14629124373657137 0 1  .3333333333333333                 .  1 .  . . 0                    .  3.333333  3
    1 0 1 1 1  .6930733259357975 0 1 1.3333333333333333                 .  9 .  . . 0                    . 13.333333 13
    1 0 0 2 1  .5554993045631528 0 1 1.6666666666666665                 .  8 .  . . 0                    . 16.666666 16
    1 0 0 6 4 .23642515629258887 0 1  .6666666666666666                 .  3 .  . . 0                    .  6.666667  6
    0 0 0 6 1  .2888530710771261 0 1  .3333333333333333                 .  5 .  . . 0                    .  3.333333  3
    1 0 0 3 1  .4088562831270797 0 1  .6666666666666666                 .  7 .  . . 0                    .  6.666667  6
    1 0 0 2 3  .7048182691423677 0 1                  1                 . 10 .  . . 0                    .        10 10
    1 1 0 2 2  .6333538983172218 1 1                  1 .3333333333333333 16 9 10 8 3   .05971942761857574        10 10
    1 1 1 5 3  .2881297448796828 1 1                  1 .3333333333333333 12 5  4 3 3 .0007233261974433081        10 10
    1 1 1 1 1  .6930733259357975 1 1                  1 .3333333333333333 17 9 10 8 3                    0        10 10
    1 1 1 2 1  .5554993045631528 1 1                  1 .3333333333333333 14 8  9 7 3                    0        10 10
    1 1 0 2 2  .6333538983172218 1 1                  1 .3333333333333333 15 9 10 8 3   .05971942761857574        10 10
    1 1 1 5 1 .17480944488523578 1 1                  1                 0 11 2  1 3 3  .008726538480995832        10 10
    0 1 1 5 2  .5035916419173779 1 1                  1                 0 13 8  7 6 3  .051907662645774844        10 10
    end
    label values gender Gender
    label def Gender 0 "Female", modify
    label def Gender 1 "Male", modify
    label values smoking Smoking
    label def Smoking 0 "Nonsmoker", modify
    label def Smoking 1 "Smoker", modify
    label values socialdeprivation social
    label def social 1 "Most deprived", modify
    label def social 7 "Least deprived", modify
    label values ethnicity Ethnicity
    label def Ethnicity 1 "White", modify
    label def Ethnicity 2 "Asian", modify
    label def Ethnicity 3 "Black African", modify
    label def Ethnicity 4 "Mixed", modify
    label values _treated _treated
    label def _treated 0 "Untreated", modify
    label def _treated 1 "Treated", modify
    label values _support _support
    label def _support 0 "Off support", modify
    label def _support 1 "On support", modify
    Attached Files

  • #2
    byhist is from SSC. (People are asked to say where community-contributed commands come from; who wrote them is less revealing for people wanting to download them too.)

    Here it is not working well for you and there may be an easy fix, but from what I understand something like

    Code:
    graph bar (sum) intp,  over(smoking) over(gender) asyvars
    gets you there directly -- and you can sum a variable that isn't integer-valued.

    Comment

    Working...
    X