Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Joerg Luedicke <joerg.luedicke@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: Creating Dummy variables with names from underlying variables |
Date | Fri, 14 Dec 2012 12:30:21 -0500 |
This would be one possibility: levelsof zipcode, local(zip) foreach i of numlist `zip' { gen zip_`i'=zipcode==`i' } Joerg On Fri, Dec 14, 2012 at 12:14 PM, Ben Hoen <bhoen@lbl.gov> wrote: > Hi all, > > I have been noodling around with this for a bit and although I have found > many posts of how to create dummy variables (e.g., > http://www.stata.com/support/faqs/data-management/creating-dummy-variables/) > , and how to apply values to labels (e.g., labmask), I have not yet found a > way to name variables after the values used to create the dummy variables. > > I have a set of 30 or so zipcodes, that I want to create dummy variables > for, and which I would like to name for their respective zipcodes, e.g, > zip_08458, zip_25468, etc... > > Take, for example: > > set seed 1234 > sysuse auto, clear > gen zipcode = 21210+ceil(5*runiform()) > tab zipcode, g(zip_) > > In this example I have five different zipcodes for which I created five > unique dummy variables. I would like to be able to create or change the > name of the existing dummy variables "zip_1", "zip_2" etc. to include their > respective zip codes. Therefore the names of the dummy variables would > ideally be "zip_21211", "zip_21212", "zip_21213", "zip_21214", and > "zip_21215". > > Any ideas? > > Thanks, as always, in advance. > > Ben > > > Ben Hoen > Principal Research Associate > Lawrence Berkeley National Laboratory > Office: 845-758-1896 > Cell: 718-812-7589 > bhoen@lbl.gov > http://emp.lbl.gov/staff/ben-hoen > > Visit our publications at: > http://emp.lbl.gov/publications > > > > > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/