Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AW: st: xttrans accuracy

From   "Martin Weiss" <>
To   <>
Subject   AW: st: xttrans accuracy
Date   Wed, 23 Jun 2010 09:32:10 +0200


Note that there might be copyright issues re NJC`s -ssc d xttrans2-, though...


-----Ursprüngliche Nachricht-----
Von: [] Im Auftrag von Maarten buis
Gesendet: Mittwoch, 23. Juni 2010 09:28
Betreff: Re: st: xttrans accuracy

--- On Tue, 22/6/10, Dmitriy Krichevskiy wrote:
> I am trying to calculate limiting distribution based on the
> matrix produced by -xttans- . the issue is that -xttrans-
> produces (or sat least shows) rounded results (such that
> often probability adds up to .9999 and not 1) which
> complicates solving the system of equations. I feel
> uncomfortable adding/subtracting  arbitrary .01's here and
> there to make things work, Is there a way to produce more
> accurate estimate via -xttrans- or otherwise?

-xttrans- is a short and simple command, as you can see by
typing -viewsource xttrans.ado-. It is thus fairly straightforward
to change it so that it returns the matrix that you are looking for,
which will allow you to work with it with more precision. In the 
changed version below I added just three lines, which results in 
-xttrans2- leaving behind a matrix called r(result) containing the
raw counts on which the proportions are based. 

*--------------------------- begin example ------------------------
program drop _all

*! version 1.0.0 23Jun2010 MLB
*! based on -xttrans-
program define xttrans2, rclass byable(recall) sort
        version 6, missing
        syntax varname [if] [in] [, Freq I(varname) T(varname) ]
        xt_iis `i'
        local ivar "`s(ivar)'"

        xt_tis `t'
        local tvar "`s(timevar)'"

        if "`freq'"!="" {
                local opts "row freq"
        else    local opts "row nofreq"

        tempvar touse
        mark `touse' `if' `in'
        markout `touse' `varlist' `ivar' `tvar'

        tempvar was is
        quietly { 
                sort `ivar' `tvar' 
                by `ivar': gen float `was' = `varlist' if _n<_N
                by `ivar': gen float `is'  = `varlist'[_n+1] if _n<_N
                local lbl : var label `varlist'
                if "`lbl'"=="" { 
                        local lbl "`varlist'"
                label var `was' "`lbl'"  
                label var `is' "`lbl'"
                by `ivar': replace `touse'=0 if `touse'[_n+1]==0 & _n<_N
        tempname result                               // <-- new 
        tabulate `was' `is' if `touse', `opts' nokey ///
                  matcell(`result')                   // <-- new
        ret add
        return matrix result `result'                 // <-- new

webuse nlswork, clear
xtset id year
xttrans2 msp
return list
*--------------------- end example -----------------------------

Hope this helps,

Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen


*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index