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 at the end of May, and its replacement, statalist.org is already up and running.


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

Re: AW: st: Grouping variables


From   mmolina@uniroma3.it
To   statalist@hsphsun2.harvard.edu
Subject   Re: AW: st: Grouping variables
Date   Fri, 5 Mar 2010 16:45:54 +0100 (CET)

Dear all,
thanks for all the advices.
It's true what many of you pointed: I have aprox 5.300 cities and less
than a hundred provinces...so seems very tedious.
The fact is that they cities are obviously codified (cancelling the last
two digits of cities we obtain provinces) but in the survey the answers
were names and no codes. So I think I should merge with some codes and
then as suggested by Martin, "assign numeric identifiers, and use a -value
label- to represent the strings..."
Best,
Alejandra

Dear,


I realize there is a lot of coding. But there is a workaround! Try to get
a list from an external source (eg. USPS, national post service, ...) with
the provinces, cities or maybe zip-codes.
If you can find this, you can merge the file.

merge m:1 city using usps


Hope this can help!

Kind regards,

Steven Gorlé


Op 5/03/2010 14:32, Martin Weiss schreef:

<>

" Better still, assign numeric identifiers, and use a -value label- to
represent the strings..."


As in:


*************
clear*
inp str1 city
a
b
c
d
e
f
g
end

gen byte province=inlist(city, "b","c","d")+ /*
*/ 2*inlist(city, "e","f","g")+3*inlist(city, "a")

la def prov 1 "a" 2 "b" 3 "c"
la val province prov

list, noo
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Martin Weiss
Gesendet: Freitag, 5. März 2010 14:27
An: statalist@hsphsun2.harvard.edu
Betreff: AW: st: Grouping variables


<>

"

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 them:


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


HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Katya Mauff
Gesendet: Freitag, 5. März 2010 14:00
An: statalist@hsphsun2.harvard.edu
Betreff: Re: st: Grouping variables

Dear Alejandra

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 cities/provinces.
Perhaps someone else can come up with a quicker way to do it.





<mmolina@uniroma3.it>  2010/03/05 02:47 PM>>>

Dear Statalits,
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 me
how to assign different cities to one province?
Thanks in advance.
Best regards,
Alejandra



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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   |   Site index