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 columns based on an argument


From   thomas bourveau <[email protected]>
To   [email protected]
Subject   Re: st: Drop columns based on an argument
Date   Thu, 28 Mar 2013 19:06:34 +0100

Dear all,

thanks a lot your solutions worked perfectly to solve my two problems.

To answer to Jeph, it turns out that I was extracting data using a set
of identifiers from Datastream (stock prices data) and if Datastream
does not recognize the firm ID it still produces a empty colum with
only a message error in the place of the ID.

Best,
Thomas

2013/3/27 Jeph Herrin <[email protected]>:
> Not sure exactly what makes your identifiers "not valid", but here's how to
> fix your code and strip out your PEs all at once:
>
> forvalues i=2(1)1285{
>         replace var`i'=subinstr(var`i',"(PE)","",.)   in 1
>         if var`i'[1]=="#ERROR" {
>                 drop var`i'
>         }
> }
>
> cheers,
> Jeph
>
>
>
>
> On 3/27/2013 3:15 PM, thomas bourveau wrote:
>>
>> Dear Statalist members,
>>
>> I have a dataset that I will have to reshape but I am facing two
>> challenges for now. My dataset is currently organized as follows:
>>
>> The first column (var1) contains different dates.
>>
>> The next columns (var2-var1285) contains my variable of interest.
>> However, the first line contains the identifier of the firm and then
>> the value of the variable of interest.
>>
>>
>> My first problem is that some identifiers are not valid, and then the
>> first line returns an error message (string format). I want to drop
>> all columns with an error message. I have tried the following code:
>>
>> forvalues i=2(1)1285{
>> drop var`i' if var`i'[1]=="#ERROR"
>> }
>>
>> However, it returns the following message: "invalid syntax".
>>
>> My second problem is that the valid identifiers are of the following
>> form, 6 figures ending by (PE):
>>
>> example : 123456(PE)
>>
>> I need to eliminate the (PE) at the end of each identifier. I have
>> tried to use the regex command but it did not worked well.
>>
>> I welcome any idea !
>>
>> Thanks in advance
>> Best
>> Thomas
>>
>> --
>> Thomas Bourveau
>> [email protected]
>> 0637573925
>> *
>> *   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/



--
Thomas Bourveau
PhD Candidate - HEC Paris
+ 33 6 37 57 39 25
Skype: thomas.bourveau

2013/3/27 Jeph Herrin <[email protected]>:
> Not sure exactly what makes your identifiers "not valid", but here's how to
> fix your code and strip out your PEs all at once:
>
> forvalues i=2(1)1285{
>         replace var`i'=subinstr(var`i',"(PE)","",.)   in 1
>         if var`i'[1]=="#ERROR" {
>                 drop var`i'
>         }
> }
>
> cheers,
> Jeph
>
>
>
>
> On 3/27/2013 3:15 PM, thomas bourveau wrote:
>>
>> Dear Statalist members,
>>
>> I have a dataset that I will have to reshape but I am facing two
>> challenges for now. My dataset is currently organized as follows:
>>
>> The first column (var1) contains different dates.
>>
>> The next columns (var2-var1285) contains my variable of interest.
>> However, the first line contains the identifier of the firm and then
>> the value of the variable of interest.
>>
>>
>> My first problem is that some identifiers are not valid, and then the
>> first line returns an error message (string format). I want to drop
>> all columns with an error message. I have tried the following code:
>>
>> forvalues i=2(1)1285{
>> drop var`i' if var`i'[1]=="#ERROR"
>> }
>>
>> However, it returns the following message: "invalid syntax".
>>
>> My second problem is that the valid identifiers are of the following
>> form, 6 figures ending by (PE):
>>
>> example : 123456(PE)
>>
>> I need to eliminate the (PE) at the end of each identifier. I have
>> tried to use the regex command but it did not worked well.
>>
>> I welcome any idea !
>>
>> Thanks in advance
>> Best
>> Thomas
>>
>> --
>> Thomas Bourveau
>> [email protected]
>> 0637573925
>> *
>> *   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/



-- 
Thomas Bourveau
[email protected]
0637573925
*
*   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