Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: creating a dummy


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: creating a dummy
Date   Thu, 26 Feb 2004 13:59:48 -0000

foreach c in f s a u b { 
	gen `c' = substr(market,1,1) == "`c'" 
} 

More generally, 

gen firstchar = substr(market,1,1) 
levels firstchar, local(chars)
foreach c of local chars { 
	gen `c' = firstchar == "`c'" 
} 

Nick 
n.j.cox@durham.ac.uk 

Tumur Gunchinmaa

> I have another 
> question to ask about creating dummy.
> I have a string variable called market (in the long format) which has 
> 19 different string "values" such as 
> f1,f2,...f6,s1,...,s5,a1,...,a5,u1,u2,b1.
> I would like to create 5 dummies which would group f1-f6 into 
> dummy f, s1-s5 into dummy s, a1-a5 into dummy a and so on.

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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