Announcement

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

  • Sankey Plot for Panel Data Transition Probabilities

    Hi all, hoping to get some assistance in constructing a Sankey Plot to visualise a simple 2x2 matrix of transition probabilities using Stata 17.0. I have read the help documentation attached to the sankey_plot package (author: Fernando Rios-Avila) but am having difficulties adjusting the code examples to my panel data set.

    My data: I have a panel data set of just under 400,000 observations (about 20,000 distinct id units over 20 years). My variable of interest is a binary variable called "neet" (indicates whether an id was NEET in a given year or not) and in this example, I am restricting attention to a subgroup classified as "young20" and only considering transitions from 2019-2020 (last two years in my sample). I have constructed a 2 x 2 transition matrix to compute the probability of transitioning between "NEET" and "non-NEET" between 2019 and 2020 for this group using the code:
    Code:
    xttrans neet if young20==1 & year>2018
    Goal: I would now like to visualise the transition probabilities defined for me in the above transition matrix using a Sankey Plot (open to any other suggestions on how to visualise transition probabilities, but from some reading online understand that a Sankey Plot is typically used). Unfortunately I am unable to post my data here and am not sure if this is typically required for Statalist posts (first time posting in a couple of years)! Any guidance would be much appreciated.
    Last edited by Josephine Auer; 01 Jul 2022, 01:36.

  • #2
    Sankey plots look pretty -- those smooth curves look pleasing and there is always the possible reader buzz of how did you do that? -- but I've never seen one for one-step changes that seemed clearer than a two-way bar chart. In this case you have 2 x 2 probabilities and 2 suffice, as the probability of remaining in the same state is presumably just the complement of the probability of changing. I'd use a bar chart and label with the numbers.

    I am positive about Sankey plots where there is a series of stages, say students dropping out, changing course or proceeding in the same course on a degree programme lasting several years, but otherwise they can be a lot of work for little or no obvious gain.
    Last edited by Nick Cox; 01 Jul 2022, 02:19.

    Comment


    • #3
      HI Josephine,
      I have recently added an update to sankey_plot but not yet pushed to ssc (i want to add a couple of other things before I do).
      I think this will give you want.
      See an example below:
      Code:
      **Data management
      webuse nlswork
      xtset id year
      ** this makes your data Wide
      gen fmsp = f.msp
      ** labels the variables
      label define msp 1 Married 0 Single
      label values msp fmsp msp
      ** uses a cleaner scheme
      ssc install color_style
      set scheme white
      ** produces the sankey plot
      sankey_plot msp fmsp if msp!=. & fmsp!=., wide xlabel(1 "Before" 2 "After") title("Transition of Marital Status")
      ** or if you want slightly different palette
      color_style egypt
      sankey_plot msp fmsp if msp!=. & fmsp!=., wide xlabel(1 "Before" 2 "After") title("Transition of Marital Status")
      Hope this helps
      Attached Files
      Last edited by FernandoRios; 01 Jul 2022, 05:43.

      Comment


      • #4
        Originally posted by FernandoRios View Post
        HI Josephine,
        I have recently added an update to sankey_plot but not yet pushed to ssc (i want to add a couple of other things before I do).
        I think this will give you want.
        See an example below:
        Code:
        **Data management
        webuse nlswork
        xtset id year
        ** this makes your data Wide
        gen fmsp = f.msp
        ** labels the variables
        label define msp 1 Married 0 Single
        label values msp fmsp msp
        ** uses a cleaner scheme
        ssc install color_style
        set scheme white
        ** produces the sankey plot
        sankey_plot msp fmsp if msp!=. & fmsp!=., wide xlabel(1 "Before" 2 "After") title("Transition of Marital Status")
        ** or if you want slightly different palette
        color_style egypt
        sankey_plot msp fmsp if msp!=. & fmsp!=., wide xlabel(1 "Before" 2 "After") title("Transition of Marital Status")
        Hope this helps
        Hi Fernando,

        How can I define additional options for the sankey plot, if any?

        Thanks in advance

        Dastan

        Comment


        • #5
          Originally posted by Dastan Aseinov View Post

          Hi Fernando,

          How can I define additional options for the sankey plot, if any?

          Thanks in advance

          Dastan
          I apologize to Fernando, this is no longer necessary.

          my mistake was I didn't copy sankey_i and sankey_plot.shlp

          Comment

          Working...
          X