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: drop observations - if statement


From   Roberto Ferrer <[email protected]>
To   Stata Help <[email protected]>
Subject   Re: st: drop observations - if statement
Date   Thu, 6 Mar 2014 17:05:16 -0430

Rochelle,

I would just add that if you're not completely sure of the values of
your "missings", you can try the -trim()- function. For example,
suppose that -cusip- were to take the value "   ." (that's three
blanks) AND "  .   " (two + three blanks). Then, your command would be
leaving some "missings" behind.

This bypasses that issue:

    drop if trim(cusip) == "."

See -help trim-.

On Thu, Mar 6, 2014 at 3:42 PM, R Zhang <[email protected]> wrote:
> thanks again!
>
> I found out this statement works drop if cusip=="        ." (leading
> empty space , 1400 observations dropped)
>
> On Thu, Mar 6, 2014 at 10:43 AM, Nick Cox <[email protected]> wrote:
>> This really shouldn't be difficult. Also, I've failed as a program
>> author if my help is not clear.
>>
>> It is also crucial that you don't do anything destructive to a dataset
>> without understanding exactly what you are doing.
>>
>> As established at length in this thread
>>
>> dropmiss cusip
>>
>> will _not_ do what you want because "." does not qualify as string
>> missing to Stata. So, it appears that what you want is
>>
>> dropmiss cusip, piasm
>>
>> but
>>
>> drop if cusip == "."
>>
>> is an exact equivalent.
>>
>> Nick
>> [email protected]
>>
>>
>> On 6 March 2014 15:35, R Zhang <[email protected]> wrote:
>>> I need to drop those missing observations for my research goal.
>>>
>>> I typed findit dropmiss, and got SJ8-4 dm89_1.  and installed it.
>>>
>>> would it be dropmiss(cusip)?
>>>
>>> thanks,
>>>
>>>
>>>
>>> On Thu, Mar 6, 2014 at 10:19 AM, Nick Cox <[email protected]> wrote:
>>>> I can't answer that for you.
>>>>
>>>> It's not necessarily a good idea to -drop- observations just because
>>>> some values are missing. That depends on your research goals, and I
>>>> have no idea what they are. Also, missing values do little harm,
>>>> because Stata usually ignores them.
>>>>
>>>> It's a conditional: if you want to -drop- data with missings,
>>>> -dropmiss- (SJ) is just one tool. But it is, necessarily, no more than
>>>> a wrapper for -drop-, so whatever it does you can do by other means.
>>>>
>>>>
>>>> Nick
>>>> [email protected]
>>>>
>>>>
>>>> On 6 March 2014 15:11, R Zhang <[email protected]> wrote:
>>>>> Nick,
>>>>>
>>>>> thanks so much!   I ran di missing("."), it display 0, so . is not missing.
>>>>>
>>>>> should I still use the user written command you suggested to drop observations?
>>>>>
>>>>> -Rochelle
>>>>>
>>>>> On Thu, Mar 6, 2014 at 6:52 AM, Nick Cox <[email protected]> wrote:
>>>>>> Note also that in general Stata is highly literal when dealing with
>>>>>> strings. Indeed it could hardly be anything else.
>>>>>>
>>>>>> So, when you see instances of "." that you want to -drop- but you ask
>>>>>> that Stata -drop- instances of "", your command cannot have the
>>>>>> desired effect.
>>>>>>
>>>>>> The user-written command -dropmiss- (Stata Journal) has an option
>>>>>> -piasm-, comprehensible as "period is also string missing" for the
>>>>>> convenience of users who wish to regard "." as missing. The existence
>>>>>> of this option is evidence for the general rule, not against it!
>>>>>>
>>>>>> Nick
>>>>>> [email protected]
>>>>>>
>>>>>>
>>>>>> On 6 March 2014 10:35, Nick Cox <[email protected]> wrote:
>>>>>>> "." may seem to mean missing in two possible senses;
>>>>>>>
>>>>>>> 1. Users may employ that coding for missing, but that's a personal
>>>>>>> choice. Stata pays no special attention.
>>>>>>>
>>>>>>> 2. Stata will return numeric missing to -real(".")-
>>>>>>>
>>>>>>> . di real(".")
>>>>>>>
>>>>>>> .
>>>>>>>
>>>>>>> Notice that Stata displayed a period or stop, meaning numeric (often
>>>>>>> called system) missing.
>>>>>>>
>>>>>>> But it does that to anything that can't be translated to a number:
>>>>>>>
>>>>>>> . di real("Stata")
>>>>>>> .
>>>>>>>
>>>>>>> Is "." missing? Stata will answer this question for you
>>>>>>>
>>>>>>> . di missing(".")
>>>>>>> 0
>>>>>>>
>>>>>>> 0 means false.
>>>>>>>
>>>>>>> Nick
>>>>>>> [email protected]
>>>>>>>
>>>>>>>
>>>>>>> On 6 March 2014 03:03, R Zhang <[email protected]> wrote:
>>>>>>>> thank you Jeph!
>>>>>>>>
>>>>>>>> I did "count if missing(cusip)", it shows zero observation. but when
>>>>>>>> the data is openned in browse mode, cusip field is displayed as "." ,
>>>>>>>> is that not missing?
>>>>>>>>
>>>>>>>> On Wed, Mar 5, 2014 at 6:00 PM, Jeph Herrin <[email protected]> wrote:
>>>>>>>>> Are you sure any are missing?
>>>>>>>>>
>>>>>>>>> Try
>>>>>>>>>
>>>>>>>>>  count if missing(cusip)
>>>>>>>>>
>>>>>>>>> and see what you get.
>>>>>>>>>
>>>>>>>>> hth,
>>>>>>>>> Jeph
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On 3/5/2014 5:41 PM, R Zhang wrote:
>>>>>>>>>>
>>>>>>>>>> Hi all,
>>>>>>>>>>
>>>>>>>>>> I used the following commands to drop observations based on a string
>>>>>>>>>> variable - CUSIP- that takes missing values, i.e. delete observations
>>>>>>>>>> with missing CUSIP,
>>>>>>>>>>
>>>>>>>>>> drop if cusip==""
>>>>>>>>>>
>>>>>>>>>> cusip is str10
>>>>>>>>>>
>>>>>>>>>> (0 observations deleted)
>>>>>>>>>>
>>>>>>>>>> could you explain why "(0 observations deleted)"?
>>>> *
>>>> *   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/
>> *
>> *   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/
*
*   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