Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: how to make xttrans work for more values than allowed by default


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: how to make xttrans work for more values than allowed by default
Date   Mon, 14 Jul 2003 10:44:55 +0100

Olena Stavrunova

> I have a panel data (id and quarters) and my categorical
> variable fcat takes 81
> values.  I need to calculate transition probabilities for
> fcat and want to use
> xttrans because it produces exactly what I need. However, I get the
> message "too many values". Is there a way to make xttrans
> work for 81 values?
> I am Stata 7  user.

You are hitting some limit of -tabulate-, although
I don't know what it is. The same limit applies
in Stata 8.

Incidentally, -xttrans- calculates not transition
probabilities, but those multiplied by 100.

The following appears to produce the numbers
you want:

*! NJC 14 July 2003
*! version 1.0.7  14jan2000
program define xttrans3, rclass byable(recall) sort
	version 6
	syntax varname [if] [in] [, I(varname) T(varname) * ]

	xt_iis `i'
	local ivar "`s(ivar)'"

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

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

	tempvar was is numer denom prob
	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
		markout `touse' `was'
		markout `touse' `is'
		bysort `touse' `was' (`is') : gen `denom' = _N if `touse'
		by     `touse' `was'  `is'  : gen `numer' = _N if `touse'
		gen `prob' = 100 * `numer' / `denom'
	}

	tabdisp `was' `is' if `touse', c(`prob') `options'
	ret add
end
exit

syntax is

xttrans3 fcat, <tabdisp_options>

If you want the probabilities themselves, edit
the code to remove "100 *".

Nick
n.j.cox@durham.ac.uk

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index