Announcement

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

  • xttrans2 - calculating transitional probabilities for multiple years.

    Hi, I'm a little confused with regards to the xttrans2 command and obtaining transitional probabilites for multiple years.

    Of the cars that have an i.d number 'id' in the years 2000, 2004 and 2008 I would like to find out how many remained in their 2000 deciles in 2004 and 2008 for miles travelled broken into deciles 'deciles_miles.' The issue I'm having is that xttrans2 only report the initial and end period but not subsequent periods in between?

    Given I have created a variable 'nyear' that is equal to 3 if the i.d number is in all 3 years I was hoping to perform the xttrans2 command on years 2000 and 2004 then 2004 and 2008. However I'm having trouble as when ever I put specifications in the xttrans command I recieve an error message of some sorts.
    For example in the last line of code if I replace nyear==3 with nyear==2 in an attempt to look at years 2000 and 2004 it states there are 'no observations' and returns the error message '__000001 not found'

    Would I have to create this manually via the tab command similar to https://www.statalist.org/forums/for...or-each-period ?

    Any ideas or help would be much appreciated.


    Lastly, when I use a percentiles figure i.e. miles travelled broken into percentiles I receive the error message 'too many values' so is it possible to use a percentile value with the xttrans2 command and if not how would one create transitional probabilities for a figure broken into percentiles or even thousandths.

    Code:
    keep if year == 2000 | year == 2004 | year == 2008
    bys id: gen nyear=[_N] 
    tabstat id, stat(n) by(year)
    keep if nyear==3
    tabstat id, stat(n) by(year)
    
    xttrans2 deciles_miles if nyear==3, prob matcell(Trans)

  • #2
    You'll increase your chances of a helpful answer by following the FAQ on asking questions - provide Stata code in code delimiters, readable Stata output, and sample data using dataex.

    With user written procedures (and even some Stata provided procedures), answers often depend on someone active having used the procedure. Apparently, such a person has not come forward to respond to your question. I suggest contacting the author of xttrans2. For xttrans, sometimes it is easiest to use the interactive to see how it sets up the command or to directly replicate the example in the documentation and then move from there.

    Comment


    • #3
      Ok will do, thanks very much for the help and response.

      Comment


      • #4
        xttrans2 is a community-contributed (Phil used the older term "user written") command from SSC, as original posters are asked to explain (FAQ Advice #12).

        It's more than a little difficult to follow the problem here because you don't give a data example (FAQ Advice #12 again). Also, at some points you seem to imply that you used xttrans, although that should make no difference to getting any results.

        As far as I can follow the code you do give in #1 you throw away all data except those for 2008. That way you lose all chance of calculating transition probabilities.

        If your data are for four year periods, you should specify delta(4) to xtset. Oddly to me xttrans is unfazed by gaps. as it just works with the next value in a panel (and not first and last values only, as you state). As is documented in the help, xttrans2 was just written (by me in 2002) to extend the reporting facilities of xttrans.

        All that said, to get transitions for particular pairs of years adjacent in your (suitably sorted) dataset, you just need to specify both years. To illustrate technique I made up some data

        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input float(id year state)
        1 2000 1
        1 2004 1
        1 2008 2
        2 2000 2
        2 2004 2
        2 2008 1
        3 2000 3
        3 2004 3
        3 2008 3
        end
         
        list, sepby(id)
        
             +-------------------+
             | id   year   state |
             |-------------------|
          1. |  1   2000       1 |
          2. |  1   2004       1 |
          3. |  1   2008       2 |
             |-------------------|
          4. |  2   2000       2 |
          5. |  2   2004       2 |
          6. |  2   2008       1 |
             |-------------------|
          7. |  3   2000       3 |
          8. |  3   2004       3 |
          9. |  3   2008       3 |
             +-------------------+
        
        xtset id year
               panel variable:  id (strongly balanced)
                time variable:  year, 2000 to 2008, but with gaps
                        delta:  1 unit
        
        . xttrans2 state
        
                   |              state
             state |         1          2          3 |     Total
        -----------+---------------------------------+----------
                 1 |     50.00      50.00       0.00 |    100.00 
                 2 |     50.00      50.00       0.00 |    100.00 
                 3 |      0.00       0.00     100.00 |    100.00 
        -----------+---------------------------------+----------
             Total |     33.33      33.33      33.33 |    100.00 
        
        xtset id year, delta(4)
               panel variable:  id (strongly balanced)
                time variable:  year, 2000 to 2008
                        delta:  4 units
        
        xttrans2 state
        
                   |              state
             state |         1          2          3 |     Total
        -----------+---------------------------------+----------
                 1 |     50.00      50.00       0.00 |    100.00 
                 2 |     50.00      50.00       0.00 |    100.00 
                 3 |      0.00       0.00     100.00 |    100.00 
        -----------+---------------------------------+----------
             Total |     33.33      33.33      33.33 |    100.00 
        
        xttrans state
        
                   |              state
             state |         1          2          3 |     Total
        -----------+---------------------------------+----------
                 1 |     50.00      50.00       0.00 |    100.00 
                 2 |     50.00      50.00       0.00 |    100.00 
                 3 |      0.00       0.00     100.00 |    100.00 
        -----------+---------------------------------+----------
             Total |     33.33      33.33      33.33 |    100.00 
        
        xttrans state if inlist(year, 2000, 2004)
        
                   |              state
             state |         1          2          3 |     Total
        -----------+---------------------------------+----------
                 1 |    100.00       0.00       0.00 |    100.00 
                 2 |      0.00     100.00       0.00 |    100.00 
                 3 |      0.00       0.00     100.00 |    100.00 
        -----------+---------------------------------+----------
             Total |     33.33      33.33      33.33 |    100.00 
        
        xttrans state if inlist(year, 2004, 2008)
        
                   |              state
             state |         1          2          3 |     Total
        -----------+---------------------------------+----------
                 1 |      0.00     100.00       0.00 |    100.00 
                 2 |    100.00       0.00       0.00 |    100.00 
                 3 |      0.00       0.00     100.00 |    100.00 
        -----------+---------------------------------+----------
             Total |     33.33      33.33      33.33 |    100.00 
        
        xttrans state if inlist(year, 2000, 2008)
        no observations
        If you did want transitions from first to last in a panel with more than 2 observations, you would need a different technique.

        See https://www.stata.com/meeting/boston...14_nichols.pdf for a thorough survey of technique in this territory.

        Comment


        • #5
          Thank you so much Nick. Apologies for not using a data example it's proprietary.

          You're answer sheds a load of light on my problem, it really cleared up a lot. Thanks for taking the time to respond.

          Comment


          • #6
            Glad it was of help.

            But we have already explained -- https://www.statalist.org/forums/help#stata -- that you can (should) phrase problems in terms of shared datasets or give fake datasets if you can't give real data. "it's proprietary" as an excuse underlines that you should please study the FAQ Advice before your next post.

            Comment


            • #7
              As always Nick you're dead right. I'll give the FAQ a thorough study before I post again.

              Thanks!

              Comment

              Working...
              X