Announcement

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

  • Plotting Percentage Shares over Continuous Variable

    Dear Statalisters,

    I have a continuous variable X (= 0 ~ 300) and a set of binary variables (say, Y, Z, W). My goal is to plot 3 curves each representing the percentage share that the binary variables equal to 1 along the continuous variable on the same graph.

    I am focusing on plotting just one binary variable (say, Y) for now.

    I think it is along the line as this:

    Code:
    graph bar (mean) Y, over(X)
    Except that I would like to have a smooth (kernel like) curve with optimized or pre-determined bin widths.

    I have tried to use the kdensity commands but they don't produce what I want. Any help or direction to other posts will be much appreciated.

    Thanks for your attention.




  • #2
    I'm not sure I understand what you want. But maybe
    Code:
    lowess Y X, logit
    ]
    is an example of one of the graphs you want, or at least close to it? If so, you can also use -lowess-'s -gen()- option to store what -lowess- puts on the vertical axis, apply -invlogit()- to it, repeat that for Z and W, and then plot the inverse logit transformed variables against X

    Comment


    • #3
      Yes it is exactly what I want (and now I learned the lowess command).

      This is the final code I use:

      Code:
      twoway (lowess Y X, adjust) || (lowess Z X, adjust) || (lowess W X, adjust), legend(label(1 "Y") label(2 "Z") label(3 "W"))
      Thank you so much!!

      Comment

      Working...
      X