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: Multiple imputation: conditional option using categorical variables
From
A Loumiotis <[email protected]>
To
[email protected]
Subject
Re: st: Multiple imputation: conditional option using categorical variables
Date
Tue, 1 Oct 2013 08:57:28 +0300
Hi Martijn,
No, it still works but as I noted in my previous message you have to
make sure that you set price to the pre-determined value whenever the
condition does not hold. In this case you have to set price to zero
whenever inlist(rep78,2,3) before running -ice-. Here is the modified
code:
*** Example starts
sysuse auto, clear
set seed 12345678
replace rep78=. if runiform()<.1
replace price=. if runiform()<.1
replace price=0 if inlist(rep78,2,3)
replace price=. if rep78==.
ice m.rep78 price mpg, cond(price:inlist(rep78,1,4,5)) saving(catexam,replace)
use catexam, clear
sort _mi _mj
browse
*** Example ends
Hope this helps,
Antonis
On Mon, Sep 30, 2013 at 5:47 PM, Hogerbrugge, M.J.A. (Martijn)
<[email protected]> wrote:
> Dear Antonis,
>
> The following error is returned by -ice-:
>
> Imputing Error: variable marstat_time2 has >1 value outside subgroup inlist(marstat_time1,1,.)
> r(499);
>
> In your example, the error would also show up if you change the condition from inlist(rep78,1,2,4,5) into inlist(rep78,1,4,5), for example.
> Do you have any idea how to work around this issue?
>
> Kind regards,
> Martijn
>
>
>>What exactly is the error that -ice- returns? Could you please
>>specify the complete -ice- command that returns that error that you
>>mentioned?
>>
>>Here is a nonsensical example that works. In this example price is
>>only answered if categorical variable rep78 is not equal to 3. Not
>>that I set price to missing whenever rep78 is missing and equal to
>>zero (pre-determined value) whenever rep78 is equal to 3.
>>
>>*** Example starts
>>sysuse auto, clear
>>set seed 12345678
>>replace rep78=. if runiform()<.1
>>replace price=. if runiform()<.1
>>replace price=0 if rep78==3
>>replace price=. if rep78==.
>>ice m.rep78 price mpg, cond(price:inlist(rep78,1,2,4,5)) saving(catexam,replace)
>>use catexam, clear
>>sort _mi _mj
>>browse
>>*** Example ends
>>
>>As you can see whenever rep78 is imputed to 3, -ice- automatically
>>assigns to price the pre-determined value of 0.
>>
>>Going back to my November 2010 unanswered post about the conditional
>>option and categorical variables it is clear now to me that the first
>>specification is the appropriate one. Thanks for reminding me about
>>this post. I will try to find it and bring a closure to it.
>>
>>-ice- is a user written program that can be found at
>>http://www.ucl.ac.uk/~ucakjpr/.
>>
>>Best,
>>Antonis
>>
>>On Sat, Sep 28, 2013 at 1:29 PM, Hogerbrugge, M.J.A. (Martijn)
>><[email protected]> wrote:
>>> Dear Stata users,
>>>
>>> Does anybody know how to use the "conditional"-option for categorical variables in multiple imputation using >ICE?
>>>
>>> The help file only provides an example using a dichotomous conditional variable ("female"). In that case, >imputation on a particular variable is only performed if the condition is met (for instance "female == 1"). If the >condition is false, a pre-determined value is imputed. To work correctly, the cases for which the condition is false >need to have only one value on the variable that needs to be imputed. If more than one value is observed, ICE >returns an error.
>>>
>>> In some instances, however, it is perfectly sensible to have multiple values in the variable to be imputed (for the >observations for which the condition is false). Let me provide a quick example using the variable marital status:
>>> - the categories for marital status are [1] "married", [2] "divorced", and [3] "widowed"
>>> - marital status is observed at multiple time points
>>> - once a person is divorced or widowed, he or she remains so for the remainder of the observation points
>>> - the ICE command will look like this:
>>>
>>> .conditional(marstat_time2: if inlist(marstat_time1,1,.))
>>> .conditional(marstat_time3: if inlist(marstat_time2,1,.))
>>> .conditional(marstat_time4: if inlist(marstat_time3,1,.))
>>>
>>> and so on.
>>>
>>> Thus, marital status at a later time point is not imputed if the case was either divorced or widowed at the >previous time point (i.e., not married [1] or missing [.]).
>>>
>>> Unfortunately, ICE returns an error for the reason described earlier. Is there some way to be able to do this kind >of conditional imputation nonetheless? I tried looking for previous posts on a similar issue, and found one >(http://www.stata.com/statalist/archive/2010-11/msg00708.html), but this post seems to be never been answered.
>>>
>>> BTW, I also looked into Stata's own imputation command (MI impute), but the conditional option is implimented >in a similar way, and switching commands seems not to be a way to overcome this problem.
>>>
>>> Looking forward to your responses and help.
>>> ~Martijn Hogerbrugge
>
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/