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: Manipulation of string variable using -regexm-


From   "STOLOWY, Herve" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: Manipulation of string variable using -regexm-
Date   Fri, 11 Oct 2013 18:40:07 +0200

Dear Statalisters:

Using Stata 12.1, I want to extract a portion of a string variable using
regular expressions, i.e. -regexs- and -regexm-.

My string variable has different possible values. Example:

A
A *
A *-
A *+
B
B *
B *-
B *+
etc.

I would like to get a variable with the content filled with the * or *- or
*+ or with this type of coding:

0 if not star
1 if only *
2 if *-
3 if *+

The * or *- or *+ always appear at the end on the value.

I tried the following syntax:

gen var_star =3D regexs(0) if(regexm(CurrRtg, "\*" "\*+" "\*-"))

Unfortunately, I get a * in all cases there is a * included in the value,
but I do not get the *- or *+.

I have difficulties with the syntax of -regexm-.

There is maybe another way to get the same result.

Best regards

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