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]

st: Removing variables if missing a particular observation


From   Nick Baker <[email protected]>
To   [email protected]
Subject   st: Removing variables if missing a particular observation
Date   11 Apr 2013 15:57:05 +0100

Hi all, I have a sample of mutual fund returns data and I wish to analyse only those funds with returns over a particular time period. Currently my data is of the format:

Date     fundret1   fundret3   fundret4
2004m3          .        2.2       3.15
2004m4 . 3.1 -1.5 2004m5 2.3 . 2.1
2004m6        1.1          .        1.8


I have two problems. I want to delete all variables that have a missing value for 2004m3. At the moment I am trying the following:

foreach var of varlist _all {

drop `var' if missing(`var') in 1
}

since 2004m3 is the first observation, but this is not working.

A second problem is that I wish to loop over all funds. They are numbered from 1 to 4722 but due to some prior deletions the sequence of funds does not include every value. I do not want to use _all because the dataset will include variables other than fund returns eventually. Any ideas if it possible to create a loop in such circumstances?

Many Thanks,

Nick Baker




*
*   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