Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: Drop columns based on an argument

From   "Cohen, Elan" <>
To   "" <>
Subject   st: RE: Drop columns based on an argument
Date   Wed, 27 Mar 2013 19:26:44 +0000

For your first problem, try:

forvalues i=2(1)1285{
  if var`i'[1]=="#ERROR"  {
    drop var`i' 

For the second,

replace id = substr(id,1,strpos(id,"(")-1)

Just make sure every id contains an open parenthesis.


- Elan

-----Original Message-----
From: [] On Behalf Of thomas bourveau
Sent: Wednesday, March 27, 2013 15:16
Subject: st: Drop columns based on an argument

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

Thomas Bourveau
*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index