Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

st: RE: Creating Dummy variables with names from underlying variables


From   "David Radwin" <dradwin@mprinc.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Creating Dummy variables with names from underlying variables
Date   Fri, 14 Dec 2012 09:24:14 -0800 (PST)

Ben,

Try -dummieslab- (Philippe Van Kern & Nicholas J. Cox) from SSC.

. rename zipcode zip
. dummieslab zip

David
--
David Radwin
Senior Research Associate
MPR Associates, Inc.
2150 Shattuck Ave., Suite 800
Berkeley, CA 94704
Phone: 510-849-4942
Fax: 510-849-0794

www.mprinc.com


> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-
> statalist@hsphsun2.harvard.edu] On Behalf Of Ben Hoen
> Sent: Friday, December 14, 2012 9:15 AM
> To: statalist@hsphsun2.harvard.edu
> Subject: st: Creating Dummy variables with names from underlying
variables
> 
> 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/


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