Announcement

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

  • Category switching

    Dear Stata-listers,

    I have a panel-data setting in which a category variable has the following dummy groups: 00, 01, 10, and 11.

    I am trying to create a table that is able to show the frequency of switches between categories, i.e. from 00 to 01, 10 and 11; from 01 to 00, 10 and 11, etc. So, row and column headers are the same category groups and the table is populated by frequency stats.

    Any help on how I can do this in Stata would be great. I am using Stata 13.1.

    Rohit

  • #2
    Hi Rohit,

    nice problem. I would advise you to set the table to long first (see -help reshape- for that).

    When/if your data are long, perform the following :
    Code:
    sort id time
    rename category current_category
    gen next_category = current_category[_n+1]
    This should get you this configuration :
    ID current_category next_category time
    ab 00 01 1
    ab 01 02 2
    cd 11 11 1
    cd 11 10 2





    Then you can do a tabulate current_category next_category, missing
    Cheers, I hope this helps.
    Joseph


    EDIT : I'm afraid I've mistaken : beware that when you do gen next_category = current_category[_n+1] the last observation of each ID will be defined from the next category of the next ID. So perhaps you should try something like egen next_category = current_category[_n+1], by(ID)
    Last edited by Joseph Chrestien; 28 Sep 2015, 07:02.

    Comment


    • #3
      PS. By the way, has anybody heard of Sankey diagrams in Stata ? Nick Cox : do you think they will be featured someday ?

      Comment


      • #4
        Thanks, Joseph! Will give it a shot and see how this performs.

        Comment


        • #5
          for a more general answer, see the help for xttab (which will also give you the help for xttrans)

          Comment


          • #6
            Thanks, Rich! xttrans seems be exactly what I wanted. Joseph's solution is intuitive too. Thanks, both!

            Comment


            • #7
              Austin Nichols gave a tremendous talk on transition probabilities etc. at the last Boston meeting. See http://www.stata.com/meeting/boston1...14_nichols.pdf

              #3 Sankey diagrams: All I can say for sure is that I have no plans to write such a routine. I find such diagrams impressive rather than directly informative.

              I can't (fore)tell what anyone else might write. It doesn't seem like the kind of thing that Stata developers much want to implement, but that's just my wild guess.

              Comment

              Working...
              X