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 at the end of May, and its replacement, is already up and running.

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

Re: st: reading dataset if

From   Nick Cox <>
Subject   Re: st: reading dataset if
Date   Wed, 21 Sep 2011 23:12:12 +0100

You are reaching towards some kind of regular expression test but ==
is a test for equality.

use dataset.dta if inlist(substr(diagp,1,1), "I", "J")

use dataset.dta if substr(diagp,1,1) == "I" | substr(diagp,1,1) == "J"

Regular expressions are also possible here:

. di regexm("Janvier", "^[IJ]")

. di regexm("jeunesse", "^[IJ]")

. di regexm("Jeunesse", "^[IJ]")

use dataset.dta if regexm(diagp, "^[IJ]")

On Wed, Sep 21, 2011 at 10:46 PM, Emmanuelle Lavaine
<> wrote:

> I have a huge dataset and I would like to get rid of some observations
> when opening it.
> I want to open my dataset only if the first character corresponds to
> 'I' or 'J'
> for the string variable 'diagp', I have something like:
> diagp
> I236
> I256
> I52
> J46
> J856
> H343
> etc..
> I tried:
>   use 'dataset.dta' if diagp=="[I-J]*"
> But I am doing something wrong and I can't figurate it out.

*   For searches and help try:

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