Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: how to cut string variables

From   n j cox <[email protected]>
To   [email protected]
Subject   Re: st: how to cut string variables
Date   Thu, 07 Jul 2005 17:10:23 +0100

If your variable contains just one letter followed by a number,
you can extract the first character and then use -tabulate-
to generate dummies.

gen srank = substr(rank,1,1)
tab srank, gen(rank)


foreach l in `c(ALPHA)' {
qui count if index(Rank, "`l'")
if r(N) > 0 gen rank`l' = index(Rank, "`l'") > 0

[email protected]

Reka Sundaram-Stukel

I am trying to cut a variable so that I just keep the string portion of it. I have search the help for various options but it seems if you don't have a uniform stub you can't cut.

For example: my variable is:

Id Rank

1 A2
2 B3
3 D5
4 E10
5 A1
6 B3

What I would like to create a variable as follows: dummy=1 if rank contains "b"

How can I do this simply so I don't have to either cut or split the variable (at least I can't figure out how to do this).
Any help would be much appreciated.

* For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index