In addition to solutions already suggested, the -dummieslab- utility might be your friend here:
ssc describe dummieslab
For example
sysuse auto
encode make , gen(make2)
dummieslab make2
dummieslab make2 , template("cardummy_@")
(see the -dummieslab- help for variations on naming possibilities)
Philippe
> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of tom j
> Sent: Friday, November 13, 2009 3:06 PM
> To: [email protected]
> Subject: st: dummy variable name from a string variable
>
> 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:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
*
* 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/