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

Re: st: dummy variable name from a string variable

From   Ada Ma <>
Subject   Re: st: dummy variable name from a string variable
Date   Fri, 13 Nov 2009 14:13:52 +0000

You have only 10 city codes, I presume?

One way to do it is to:

for any NY (put all your city codes here): gen citydummy_X=city=="X"

Note.  One, this is a v old Stata command but it still works.  Two,
whatever behind the colon, you put X in places where you want your
city codes appear, regardless of whether they are in the string
variable, in the variable name, etc.


On Fri, Nov 13, 2009 at 2:06 PM, tom j <> wrote:
> I want to create 10 dummy variables based on one string variable
> "city", which lists the city codes (like NY) of 10 cities. I can do
> this simply by (after encoding the city variable):
> tabulate city, gen(citydummy)
> This would create citydummy1 to citydummy10. What I want is to suffix
> each dummy with city codes, listed in the variable 'city' , so I have
> the dummy variables named from, for example, citydummyNY to
> citydummyAM.
> The city variable has multiple occurrences of each code. I have had a
> look at -renvars- but I don't think that alone will solve my problem.
> Any ideas?
> Tom.
> *
> *   For searches and help try:
> *
> *
> *

Ada Ma
Research Fellow
Health Economics Research Unit
University of Aberdeen, UK.
Tel: +44 (0) 1224 555189
Fax: +44 (0) 1224 550926

*   For searches and help try:

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