Bookmark and Share

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

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

st: Creating Dummy variables with names from underlying variables

From   "Ben Hoen" <>
To   <>
Subject   st: Creating Dummy variables with names from underlying variables
Date   Fri, 14 Dec 2012 12:14:49 -0500

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.,
, 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

Any ideas?

Thanks, as always, in advance.


Ben Hoen
Principal Research Associate
Lawrence Berkeley National Laboratory
Office: 845-758-1896
Cell: 718-812-7589

Visit our publications at:

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index