Statalist


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

Re: st: AW: dummy variable name from a string variable


From   tom j <tomstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: AW: dummy variable name from a string variable
Date   Fri, 13 Nov 2009 16:03:57 +0100

Thanks, Martin,
I had come close, but couldn't nail it!
Ada, I couldn't get your code running, but thanks anyway.

Tom.

On Fri, Nov 13, 2009 at 3:45 PM, Martin Weiss <martin.weiss1@gmx.de> wrote:
>
> <>
>
> No need to -encode- beforehand (unless you want to)...
>
>
>
> *************
> clear*
>
> input str2 citycode
> "NY"
> "LA"
> "HO"
> "SF"
> "CH"
> end
>
> compress
> list, noobs
>
> levelsof citycode
>
> foreach lev in `r(levels)'{
>        gen byte dummy`lev'=citycode=="`lev'"
> }
> *************
>
>
>
> HTH
> Martin
>
>
> -----Ursprüngliche Nachricht-----
> Von: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von tom j
> Gesendet: Freitag, 13. November 2009 15:06
> An: statalist@hsphsun2.harvard.edu
> Betreff: 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/
>

*
*   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/



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