Bookmark and Share

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


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

Re: st: decoding patterns for xttrans or other regression models


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: decoding patterns for xttrans or other regression models
Date   Tue, 26 Apr 2011 16:35:01 +0100

Sure. Let's first guess that your state_history variable is a string variable.

gen length = length(state_history)
expand length
bysort item : gen value = real(substr(state_history, _n, 1))
by item : gen date = ym(floor(start[1]/100), mod(start[1], 100)) + _n - 1
format date %tm_m_CY

Now let's guess that it's not a string variable. In that case, you can
use the technique above after conversion to a string, or devise your
own alternative.

Nick

On Tue, Apr 26, 2011 at 2:10 PM, Argyn Kuketayev
<[email protected]> wrote:

> I have the data set, where each observation has the following format:
>
> item#,state_history,start_month,end_month
> 1,111232100,201001,201009
> 2,1232100,201002,201008
>
> The second column is similar to what is produced by -xt- commands with
> -pattern- option.
>
> I need to convert the above compressed format into:
> 1,1,201001
> 1,1,201002
> 1,1,201003
> 1,2,201004
> 1,3,201005
> 1,2,201006
> 1,1,201007
> 1,0,201008
> 1,0,201009
> 2,1,201002
> 2,2,201003
> 2,3,201004
> 2,2,201005
> 2,1,201006
> 2,0,201007
> 2,0,201008
>
> because I think that -xttrans- and -logit- commands would need in this
> format, i.e.
> item#,state,month
>
> is there an easy way of doing this in Stata? I've been decoding the
> history field outside Stata 11 so far, but maybe it can do it for me.
>
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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