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: Re: stata generated wrong lagged values for mi data
From
[email protected]
To
[email protected]
Subject
Re: st: Re: stata generated wrong lagged values for mi data
Date
Fri, 4 Jun 2010 09:42:02 -0400 (EDT)
The mi xeq: command sovles the problem of my data. Thanks,Yulia,Wes and
Martin.
Junqing
> Junqing <[email protected]> asks how to generate a lagged variable for
> MI
> data:
>
>> My data is panel data in mi format. I used the following syntax to
>> generate
>> several lagged variables(one time point lag) one by one:
>>
>> mi tsset ID time
>> sort ID time
>> by ID, gen lagx=l.x
>>
>> But i found that the generaged lagged values of panels were wrong. How i
>> may
>> fix it?
>
> In general, when performing data manipulation on -mi- data, it is
> important to
> use -mi- specific commands in place of the standard Stata commands when
> there
> is an -mi- specific alternative. The list of the -mi- specific commands
> can
> be found in -help mi-. If there is no -mi- specific version, before using
> the
> standard Stata construct, look first at -help mi xeq-.
>
> To obtain correct results, Junqing needs to use the -mi xeq- command:
>
> . mi tsset ID time
> . mi xeq: sort ID time; by ID: gen lagx = l.x
>
> Notice that to issue multiple commands with -mi xeq-, the commands must be
> separated by a semicolon. -mi xeq- issues all specified commands
> separately
> on m=0,1,..., where m=0 refers to the original data and m=1,... refers to
> each
> set of imputed data. Because the lag operator requires that data are
> sorted
> on the panel and time variables, it is important to use -mi xeq- to
> execute
> both the -sort- command and -by: gen- together on each m=0,1,... data.
>
> Martin Weiss demonstrates an example without using -mi xeq- which returns
> results as expected:
>
>>
>> ***
>> clear*
>> set obs 100
>> //id
>> gen id=_n
>> //expand to # of time periods
>> expand 10
>> bys id: gen time=_n
>> gen x=rnormal()
>> compress
>> mi set wide
>> mi tsset id time
>> by id: gen lagx=l.x
>> l in 1/50, sepby(id)
>> ***
>
>
> Depending on the chosen -mi- storage style, using standard Stata commands
> can
> be appropriate as is the case in Martin's example, which used the -wide-
> style. However, it is safer to use -mi- specific commands or -mi xeq-
> because
> these will work regardless of the -mi- style.
>
> If Junqing is still experiencing difficulties, Junqing should contact
> Stata
> Technical Services at [email protected].
>
>
> -- Yulia -- Wes
> [email protected] [email protected]
> *
> * 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/
>
*
* 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/