Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

Re: st: xttrans accuracy

From   Maarten buis <>
Subject   Re: st: xttrans accuracy
Date   Wed, 23 Jun 2010 07:28:11 +0000 (GMT)

--- 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:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index