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

Re: st: mi in Stata 11

From (Yulia Marchenko, StataCorp LP)
Subject   Re: st: mi in Stata 11
Date   Sun, 09 Aug 2009 16:17:48 -0500

JIBONAYAN RAYCHAUDHURI <> had a follow-up question to my
earlier response at

> Just to be clear, before typing :
> . mi register imputed y1 y2 y3 
> We would have to use : 
>. mi reshape y, i(id) j(time)
> to get the data to wide form? Also, the simple reshape command has a long
> and wide option, but mi reshape does not require this declaration? 

If your -mi- data are originally in long form, you should use -mi reshape
wide- to reshape it to wide form before imputation:

   . mi reshape wide y, i(id) j(time) 

The above will create variables y1, y2, and y3, provided that 'time' has three

Then use -mi reshape long- to convert the -mi- data back to long form after

   . mi register imputed y1 y2 y3
   . mi impute mvn y1 y2 y3, add(5)

   . mi reshape long y, i(id) j(time)

Note that -mi reshape- does require specification of -long- or -wide- in the
same way as -reshape-.  I accidentally omitted this in my earlier response.

> Finally, before any of this on the original data should we declare :
> . iis id
> . tis time
> or is there some other command for declaring a panel if we want to impute?

Because -mi impute- does not provide direct methods to impute panel data, you
do not need to declare your panel data before imputation.  After imputation
and once -mi- data are converted back to long form, you can use -mi xtset- to
declare your panel data.  (-iis- and -tis- were superseded by -xtset- as
of Stata 10.)

   . mi xtset time

Notice that variable 'time' here records panel identifiers; it is not a time
identifier.  As I mentioned in my previous post,

-mi impute- does not provide a way to impute time-series data which is what
Jibonayan has.

If Jibonayan had panel data rather than panel time-series data, the following
would be a way to proceed.

Suppose that you have longitudinal data saved in long form (mydata.dta):
variable 'y' records measurements, variable 'time' records times at which the
measurements were taken (panels), and variable 'id' records observation
identifiers within panels.  Suppose that variable 'y' contains missing data.
Here are the steps for imputing missing values in 'y'.

First, declare your data to be -mi- data.  I chose the marginal long style,

   . use mydata
   . mi set mlong					(1)

Reshape long -mi- data to wide form:

   . mi reshape wide y, i(id) j(time)			(2)

Say 'time' has three categories so the above step creates three variables
'y1', 'y2', and 'y3'.

To impute them, we must first register them as imputed:

   . mi register imputed y1 y2 y3

and then use, for example, -mi impute mvn- to fill in missing values:

   . mi impute mvn y1 y2 y3, add(5)

If you wish to convert back to long form you can use -mi reshape- again:

   . mi reshape long y, i(id) j(time)

If you now want to declare your imputed panel data, you should use -mi xtset-:

   . mi xtset time

In the above, one can replace steps (1) and (2) with the following:

   . use mydata
   . reshape wide y, i(id) j(group)               	(1)
   . mi set mlong					(2)

*   For searches and help try:

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