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: String Variable
From
Joerg Luedicke <[email protected]>
To
[email protected]
Subject
Re: st: String Variable
Date
Wed, 8 Jun 2011 10:17:15 -0400
On Wed, Jun 8, 2011 at 10:08 AM, yj <[email protected]> wrote:
> Hello, I'm a new user of STATA.
>
> I would like to generate a new variable if a concatenated string variable
> contains the character I want.
>
> eg.
>
> observation string variable
> 1 ABC
> 2 BC
> 3 AC
> 4 AFC
> 5 A
>
> I would like to create a new variable for observations where the string
> variable contains the letter A (its position in the string variable is
> irrelevant).
>
If I understand this correctly, you want to indicate whether the
string contains at least one "A"? If this is true, have a look at
-help regexm-. In your case, you could probably type something like:
gen v1=regexm(your_string_variable, "A")
Then, the new variable v1 contains the value 1 whenever "A" shows up
in your string variable, and the value 0 otherwise.
J.
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/