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]

Re: st: Generating labels


From   Carlos Valencia <[email protected]>
To   [email protected]
Subject   Re: st: Generating labels
Date   Thu, 5 Sep 2013 11:37:21 -0500

Thank you all

The way Nick said worked for me

Carlos Valencia MD
[email protected]

On Wed, Aug 28, 2013 at 11:44 AM, Nick Cox <[email protected]> wrote:
> That way is barred. A given value label can have only and only one definition.
>
> You could define
>
> egen group = group(state city)
>
> and then define labels for such a variable.
> Nick
> [email protected]
>
>
> On 28 August 2013 17:35, Carlos Valencia <[email protected]> wrote:
>> Current data is problematic because the codification of some cities is
>> repeated as follows: the main city of an state is codified by 1, the
>> second by 2 and so on. The main city of the state of Antioquia, would
>> be (Medellín), and is codified with 1 the main city of the state of
>> Cundinam (Bogota) is codified by 1 also. So, adding any label for any
>> single number of city would be misleading. So I wonder if there is any
>> way to label the number of the city, depending on the code of the
>> state (which is already labeled). I have tried something like (and
>> didn't work because of invalid syntax)
>>
>> label define cityname 1 "Medellín" if state Antioquia
>>
>> YEAR MONTH SEX STATE       CITY CITYNAME
>> 1996   11           0     Antioquia    1          ....
>> 1988   7             1     Cundinam   1          ...
>> 1982   4             1     Bolivar        1          ....
>>
>> Thanks again
>>
>> Carlos
>>
>>
>> On Tue, Aug 27, 2013 at 2:25 PM, Austin Nichols <[email protected]> wrote:
>>> Or, perhaps...
>>>
>>> clear
>>> input year month sex str20 state municip str20 municip2
>>> 1996 11  0  Antioquia 1 Medellin
>>> 1988 7   1  Cundinam  1 Bogota
>>> 1982 4   1  Bolivar   1 ...
>>> end
>>> egen i=group(state municip2)
>>> su i, mean
>>> qui forv i=1/`r(max)' {
>>> levelsof state if i==`i', loc(s)
>>> levelsof municip2 if i==`i', loc(m)
>>> loc c: di `m' ", " `s'
>>> la def i `i' `"`c'"', modify
>>> }
>>> la val i i
>>> l, noo
>>>
>>>
>>>
>>> On Tue, Aug 27, 2013 at 3:12 PM, Sarah Edgington <[email protected]> wrote:
>>>> I don't think value labels will work for this task.
>>>> If I'm understanding correctly, what Carlos wants to do is create a value
>>>> label for municip based on the text in municip2.  The problem is that the
>>>> values of municip2 vary within a given value of municip.  As far as I know
>>>> there's no way to attach multiple labels to a single value that are
>>>> different depending on the value of another variable (which is, in essence,
>>>> what would be required for value labels to work here).
>>>>
>>>> What I don't understand is why the current data is problematic.  It looks
>>>> like the string variable municip2 already contains the desired text.  I
>>>> don't see how adding another string variable would help since it seems like
>>>> you already have the text you need.  If what you're looking for is a numeric
>>>> variable to represent the city names you could use -encode- to create a
>>>> unique numeric value for every city name in the dataset.
>>>>
>>>> -Sarah
>>>>
>>>>
>>>>
>>>> -----Original Message-----
>>>> From: [email protected]
>>>> [mailto:[email protected]] On Behalf Of Nick Cox
>>>> Sent: Tuesday, August 27, 2013 11:29 AM
>>>> To: [email protected]
>>>> Subject: Re: st: Generating labels
>>>>
>>>> Sounds as if you mean _value labels_. -search labmask- and see if it does
>>>> what you want. You need to download it before you can use it.
>>>>
>>>> Nick
>>>> [email protected]
>>>>
>>>>
>>>> On 27 August 2013 19:22, Carlos Valencia <[email protected]> wrote:
>>>>> Hi, I'm new on stata
>>>>>
>>>>> I would like to add lables to some variables (or generate a new text
>>>>> variable), which have the same code as in the example , but are in
>>>>> fact, different, as in the example: The main city of the state
>>>>> "Antioquia" coded by "1" is Medellin, and the main city of the state
>>>>> "Cundinam" is 1 as well.
>>>>>
>>>>> YEAR MONTH SEX STATE       MUNICIP MUNICIP2
>>>>> 1996   11           0     Antioquia  1             Medellin
>>>>> 1988   7             1     Cundinam 1             Bogota
>>>>> 1982   4             1     Bolivar      1             ...
>>>>>
>>>>> Since there are many cities belonging to some municipalities using the
>>>>> same value, how can I handle this, without changing all the cities
>>>>> manually?
>>>>>
>>>>> Thanks by your help
>>>>> *
>>>>> *   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/
>>>> *
>>>> *   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/
>>>>
>>>> *
>>>> *   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/
>>> *
>>> *   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/
>>
>>
>>
>> --
>>
>> *
>> *   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/
>
> *
> *   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/

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