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 on April 23, and its replacement, is already up and running.

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

RE: AW: st: Grouping variables

From   "Nick Cox" <>
To   <>
Subject   RE: AW: st: Grouping variables
Date   Fri, 5 Mar 2010 15:26:46 -0000

Kit Baum discussed a good approach using -merge- in this FAQ:


Eric Booth

if you've got more than 10 cities that your assigning to a province,
inlist() will hit its limit, but you can use a loop:

	g province = ""
	local cities b c d h i j k l m n o p q r s t 
foreach c of local cities {
	replace province = "a" if city=="`c'"

On Mar 5, 2010, at 7:26 AM, Martin Weiss wrote:
> gen province=a if (city=="b"|city=="c"|city=="d")
> replace province=b if (city=="e"|city=="f"|city=="g")
> Those province identifiers would have to carry quotation marks around
> *************
> clear*
> inp str1 city
> a
> b
> c
> d
> e
> f
> g
> end
> gen str1 province="a" if inlist(city, "b","c","d")
> replace province="b" if inlist(city, "e","f","g")
> list, noo
> *************
> Better still, assign numeric identifiers, and use a -value label- to
> represent the strings...

Katya Mauff
> Try using an if statement. So for example:
> gen province=a if (city=="b"|city=="c"|city=="d")
> replace province=b if (city=="e"|city=="f"|city=="g")
> etc.
> I know it's slightly tedious, esp if you have several
> Perhaps someone else can come up with a quicker way to do it.
>>>> <> 2010/03/05 02:47 PM >>>

> In my database I have a variable, called "city" which represent firms'
> main base. It is a string variable that I've already encoded in an
> another.
> I have a lot of other information about the firms and I need to work
at a
> more aggregated level, for instance "province", could you please tell
> how to assign different cities to one province?

*   For searches and help try:

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