Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

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


From   "Ben Hoen" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: Creating Dummy variables with names from underlying variables
Date   Fri, 14 Dec 2012 13:02:20 -0500

As always, spot-on advice.  Thank you David & Jeorg!

For the list's (other similar inquirers') edification, my zip was a string,
so the corrected final example code using dummieslab (SSC) was:  

set seed 1234
sysuse auto, clear
gen zipcode = 21210+ceil(5*runiform())
tostring zipcode, replace

encode zipcode, g(zipcodetemp)
dummieslab zipcodetemp, template(zip_@) novarlabel 
drop zipcodetemp



Ben Hoen
LBNL
Office: 845-758-1896
Cell: 718-812-7589


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of David Radwin
Sent: Friday, December 14, 2012 12:24 PM
To: [email protected]
Subject: st: RE: Creating Dummy variables with names from underlying
variables

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: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Ben Hoen
> Sent: Friday, December 14, 2012 9:15 AM
> To: [email protected]
> 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
> [email protected]
> 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/

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index