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: Missing Values


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Missing Values
Date   Tue, 7 Jan 2014 18:22:56 +0000

That's not what you said, but it makes more sense. Here is some technique:

First, you show no data, so we need a sandpit to play in:

webuse grunfeld, clear
set seed 2803
replace invest = . if runiform() < 0.7

Download -tsspell- from SSC and then identify spells of missing values:

tsspell , c(missing(invest))

The length of each spell is an easy calculation

egen max = max(_seq), by(company _spell)

Then any interpolation is made conditional:

by company: ipolate invest year if max <= 5, gen(invest2)

For explanation of the _principles_ of identifying spells, see

SJ-7-2  dm0029  . . . . . . . . . . . . . . Speaking Stata: Identifying spells
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q2/07   SJ 7(2):249--265                                 (no commands)
        shows how to handle spells with complete control over
        spell specification

http://www.stata-journal.com/sjpdf.html?articlenum=dm0029


Nick
[email protected]


On 7 January 2014 17:37, Sadia Khalid <[email protected]> wrote:
> @Nick Cox
>
> I only want to fill in the missing values if the no of missing values
> are equal to or less than 5. if 5 or more values are missing than do
> not fill in the missing values.
>
> On 7 January 2014 22:31, Nick Cox <[email protected]> wrote:
>> <>
>>
>> So 5 is OK for interpolation, but 4 or 6 isn't? Sounds bizarre.
>>
>> Nick
>> [email protected]
>>
>>
>> On 7 January 2014 17:22, Sadia Khalid <[email protected]> wrote:
>>>
>>> I have read about your code for filling the in between missing values
>>> at http://www.stata.com/statalist/archive/2003-05/msg00247.html
>>>
>>> I want the code that fill the missing values only if 5 inbetween
>>> values are missing.
*
*   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/


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