Announcement

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

  • Plotting trends of a binary variable over time

    Hi all,

    I am working with pooled cross sectional data and after having done probit and marginal effects analysis, I want to find out whether it is possible to plot any sort of graph/chart that could show trends of how a binary dependent variable (y axis) has changed over time (x axis). Is there a way of converting the binary variable to a continuous scale, or perhaps I have to use the marginal effects?

    Thanks in advance!

  • #2
    I'm not sure I completely understand what you want but I think this will help:
    Code:
    help lowess
    if, following the FAQ, you were to provide a -dataex- data example, people could suggest actual code and could try things out

    Comment


    • #3
      Thank you for you response!

      A snippet from data can be seen below. I am not sure if it will be of much help but I essentially want to plot a graph showing the trend of how the "teayy" variable, which is binary, changes over time starting from 2011 and onwards. If there any way of plotting something that would show a trend in each year how many teayy=1? Thank you!

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input double(teayy yrsurv)
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      1 2011
      0 2011
      1 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      1 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      1 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      0 2011
      end
      label values teayy teayy
      label def teayy 0 "NO", modify
      label def teayy 1 "YES", modify

      Comment


      • #4
        One approach would be to collapse the data so that it shows the proportion of teayy == 1 for each year, and then graph that proportion. Many relevant graph types are available; see -help twoway-. Note that your example data has no variation in year, so it does not enable a display of trend by year:

        Code:
        // Make useful example data.
        clear
        set seed 4643
        set obs 10
        gen int yrsurv = 2010 + _n
        gen int nperyear = 80 + ceil(50 * runiform())
        expand nperyear
        bysort yrsurv: gen teayy = ///
           (runiform() > (0.6 + 0.02 * (2011-yrsurv)))
        // end example data
        //
        collapse (mean) propteayy = teayy, by(yrsurv)
        label var propteayy "Proportion teayy == 1"
        twoway (connected propteayy yrsurv)

        Comment


        • #5
          Thank you! Yes, the example data only has 2011 but my actual data has more years. Would this show teayy=1 as a proportion all the teayy observations? What if I would also like to compare two countries in one graph for variable teayy=1? How would I collapse the data then? Thanks in advance!

          Comment

          Working...
          X