Announcement

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

  • xttrans for each period?

    Hi,

    I just asked a question on Cross Validated. Just after I posted it, I figured it is probably more at home here. So here it comes again:

    I am using Stata 13 to estimate a few models with some panel data I have. Among others, I am interested in reporting transition probabilities fot the change in one categorical variable over time. Fortunately, Stata is providing xttrans as a convenient way to do this.

    I have three questions:

    (1) what transition probabilty is xttrans reporting? The help file only shows an example with cross sectional data. Apparently it estimates the probabilty of xit+1=v2 given that xit=v1. Yet, I am wondering, what is the final state in a panel setting with t>2?

    (2) And moreover, is it possible to report transition rates for each period in revolving manner? Such as p1 equals the probabitly for xit+1=v2 and p2 that of xit+2=v2 and so on?

    (3) And lastly, is there a good way to plot such periodical transition rates over time in Stata?

    You can find the original (cross)post in the via the link attached.

    Thank you very much in advance!
    /R
    I am using Stata 13 to estimate a few models with some panel data I have. Among others, I am interested in reporting transition probabilities fot the change in one categorical variable over time.

  • #2
    I would say that post is off-topic on Cross Validated, and I've voted to that effect, but thanks for telling us about it.

    Austin Nichols gave a great talk on this topic at the Boston meeting in 2014. http://www.stata.com/meeting/boston1...14_nichols.pdf

    Comment


    • #3
      Thank you Nick, the presentation is indeed very helpful. So given that I can use tab rather easily, can I specify which transition probability (that is, for which start and end period) I want to report via the if expression?

      To make it a bit more tangible, I adapted Austin Nichols example to the following:

      Code:
      webuse nlswork, clear
      keep if inlist(year, 70,71,72,73,77,78)
      egen m=median(ln_wage), by(year)
      gen above=ln_wage>m if ln_wage<.
      gen nextyr=f.above
      
      tab above nextyr, nofreq row
      tab above nextyr if year>=70 & year<=71, nofreq row
      tab above nextyr if year>=71 & year<=72, nofreq row
      tab above nextyr if year>=72 & year<=73, nofreq row
      tab above nextyr if year>=73 & year<=74, nofreq row /*no observations*/
      tab above nextyr if year>=74 & year<=75, nofreq row /*no observations*/
      tab above nextyr if year>=76 & year<=77, nofreq row /*no observations*/
      tab above nextyr if year>=77 & year<=78, nofreq row
      And if my assumption is right, is there a way to plot the transition rates over time?

      Thanks,
      /R

      Comment


      • #4
        That's a good example to work from. Yes, you can save the tabulation results to a matrix each time and then push the frequencies into new variables.

        Note that you should select a single year for the tabulate. The transition to the next year is already in the variable you created,

        NB corrected from first posting.

        Code:
        webuse nlswork, clear
        keep if inlist(year, 70,71,72,73,77,78)
        egen m=median(ln_wage), by(year)
        gen above=ln_wage>m if ln_wage<.
        gen nextyr=f.above
        
        quietly { 
        
        forval j = 1/4 { 
            gen f`j' = . 
        } 
        
        local i = 1 
        
        forval y = 70/77 { 
            count if above < . & nextyr < . & year == `y'
            if r(N) > 0 { 
                tab above nextyr if year == `y', row matcell(work) 
                replace f1 = work[1,1] in `i' 
                replace f2 = work[1,2] in `i' 
                replace f3 = work[2,1] in `i' 
                replace f4 = work[2,2] in `i'
            }     
            local ++i 
        } 
        
        gen p11 = f1 / (f1 + f2) 
        gen p12 = f2 / (f1 + f2) 
        gen p21 = f3 / (f3 + f4) 
        gen p22 = f4 / (f3 + f4) 
        
        } 
        
        gen myyear = 69 + _n 
        format p* %04.3f 
        list myyear f* p* if f1 < . , sep(0) 
        
               +----------------------------------------------------------------+
               | myyear    f1    f2    f3    f4     p11     p12     p21     p22 |
               |----------------------------------------------------------------|
            1. |     70   454   160    94   607   0.739   0.261   0.134   0.866 |
            2. |     71   439   126    98   561   0.777   0.223   0.149   0.851 |
            3. |     72   557   128    57   669   0.813   0.187   0.079   0.921 |
            8. |     77   671   115   127   712   0.854   0.146   0.151   0.849 |
               +----------------------------------------------------------------+
        Last edited by Nick Cox; 22 Jul 2015, 05:03.

        Comment


        • #5
          Dear Nick, thank you so much!!!!
          This is truly great! I adapted your beautiful code and it works just perfect for my example.

          One (I can't promise but I hope) last question: I think it would be great to graph the transitions rates (p11, p12, p21, p22) over time. Do you think there is a way to do this?

          Comment


          • #6
            You have the variables already set up:

            Code:
             
            twoway connected p* myyear

            Comment


            • #7
              I don't knwo what to say... thank you so much! I posted that you provided a great answer (as a comment) on the Cross Validated post too - just for the sake of completeness.

              Comment


              • #8
                Thanks for the double closure.

                Comment

                Working...
                X