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: Make categories from a list within a variable


From   "David Radwin" <[email protected]>
To   <[email protected]>
Subject   st: RE: Make categories from a list within a variable
Date   Fri, 26 Oct 2012 10:32:36 -0700 (PDT)

This solution requires you to list all the categories in the first line,
but I think that's a good idea because it requires you to exercise some
discretion in what constitutes a valid category for your purposes. Entries
like "bohemian" and "east european" are not countries per se, but they
might be acceptable for this purpose.

Also notice the compound quotation marks for multi-word categories like
"east european".


foreach nationality in `"east european"' german spanish french etc {
	local nationalityvar = subinstr("`nationality'"," ","_",.)
	gen `nationalityvar' = strpos(lower(varname), "`nationality'") > 0
	}


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 Lynne Morgan
> Sent: Friday, October 26, 2012 9:53 AM
> To: [email protected]
> Subject: st: Make categories from a list within a variable
> 
> Hello,
> 
> I have a variable that asks about country of origin. Unfortunately, my
> data entry people were not consistent, so I ended up with things like
> this:
> 1    german
> 2    french, german, spanish
> 3    FRENCH GERMAN
> 4    finnish,irish,english,french,german, bohemian
> 5     polish and german
> 6    swedish & east european
> 
> How can I search this variable and create an indicator variable for each
> ethnicity based on the string? Can I search within the string to find a
> keyword?
> *What is the proper lingo for the bolded text?
> 
> gen german = 0
> replace german = 1 if coorigin contains "german"
> 
> 
> Thanks!!
> 
> --
> Lynne Morgan, MPH
> Assistant Researcher
> Survey of the Health of Wisconsin
> University of Wisconsin, Madison
> (e) [email protected]
> (p) 608-821-1243

*
*   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