Announcement

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

  • Search value in a matrix

    Dear all,

    I am working on a panel dataset, where I classified individuals into groups according to some characteristics of their variables. Then, using the command xttrans2, I got the transition probabilities and frequencies of moving from one group to each other. I have run the xttrans2 command conditional on ages, in order to get the transition probabilities from each group when an individual is 18 years old (to 19 years), when an individual is 19 years old (to 20 years) and so on.

    Above there is the code I wrote: in the first part I create the groups (and call them 111, 123, ... with the forvalues loop), in the second part I use the xttrans2 command and transfer to Excel the results.

    Code:
    _pctile I, p(25, 50, 75)
    scalar I25 = r(r1)
    scalar I50 = r(r2)
    scalar I75 = r(r3)
    quietly sum I
    scalar I0 = r(min)
    scalar I100 = r(max)
    
    _pctile L, p(50)
    scalar L50 = r(r1)
    quietly sum L
    scalar L0 = r(min)
    scalar L100 = r(max)
    
    
    _pctile IL, p(33, 66)
    scalar IL33 = r(r1)
    scalar IL66 = r(r2)
    quietly sum IL
    scalar IL0 = r(min)
    scalar IL99 = r(max)
    
    gen group = 0
    
    forvalues i = 25(25)100 {
    forvalues j = 50(50)100 {
    forvalues k = 33(33)99  {
    
    local ii   = `i'/25
    local jj   = `j'/50
    local kk = `k'/33
    
    replace group = `ii'`jj'`kk' if ///
                            I <= I`i' & I >= I`=`i' - 25' & ///
                            L <= L`j' & L >= L`=`j' - 50' & ///
                            IL <= IL`k' & IL >= IL`=`k' - 33'  
    
                            }
                            }
                            }
    
    forvalues i = 18/89 {
    
    preserve
    drop if AGE < `i' | AGE > `i' + 1                    
    
    quietly xttrans2 group, freq matcell(Mf`i')
    quietly xttrans2 group, prob matcell(Mp`i')
    putexcel A1 = matrix(Mp`i', names) using Transition, modify sheet("AGE`i'", replace) keepcellformat
    
    restore
    }
    Now the question.
    I would like to create and put to excel a vector for each combination of two groups (start and arrive groups) in order to be able to plot the change of those probabilities over the ages.
    To give an example, I am trying to create a vector of the form (including a missing value at AGE 24):
    AGE 18 19 20 21 22 23 24 25 26
    from group "111" to group "121" 0.8 0.4 0.5 0.6 0.3 0.2 . 0.6 0.7
    The big issue is that not all the transition matrices created with xttrans2 have the same dimension as there are some missing values and not all the probabilities of all groups have been calculated.
    I apologize for the long question, thanks in advance for any help!

    Sincerely
    Luca

  • #2
    You're asked (FAQ Advice #12) to explain the provenance of user-written programs you refer to. In this case xttrans2 is from SSC and dates from 2001 and 2002. I can tell you that the author hasn't thought about it seriously since. Any application of xttrans2 doesn't know about any other, so resulting matrices aren't bound to be consistent.

    http://www.stata.com/meeting/boston1...14_nichols.pdf gave an overview of estimating transition probabilities. I suspect that Austin's criticism of xttrans carries over to xttrans2.

    I don't have an easy solution for you in combining these matrices. I am not even convinced that the problem is best tackled this way without an enormous dataset.

    Comment


    • #3
      EDIT

      Originally posted by Nick Cox View Post
      You're asked (FAQ Advice #12) to explain the provenance of user-written programs you refer to. In this case xttrans2 is from SSC and dates from 2001 and 2002. I can tell you that the author hasn't thought about it seriously since. Any application of xttrans2 doesn't know about any other, so resulting matrices aren't bound to be consistent.

      http://www.stata.com/meeting/boston1...14_nichols.pdf gave an overview of estimating transition probabilities. I suspect that Austin's criticism of xttrans carries over to xttrans2.

      I don't have an easy solution for you in combining these matrices. I am not even convinced that the problem is best tackled this way without an enormous dataset.
      Thanks Nick for the answer.
      I apologize for the provenance, if needed the STATA help file is at the following link: http://www.stata.com/manuals13/xtxttab.pdf

      In addition to the suggested slides, I also read your post http://www.stata.com/statalist/archi.../msg01110.html and understood the critique.
      Once fixed the problem using tab, how would you suggest to proceed to get the needed results?

      Thanks!

      Luca

      Last edited by Luca Gagliardone; 13 Jan 2017, 12:22.

      Comment

      Working...
      X