Statalist


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

Re: AW: st: AW: generating count and sum variable over two different categorical variables


From   moleps <[email protected]>
To   [email protected]
Subject   Re: AW: st: AW: generating count and sum variable over two different categorical variables
Date   Mon, 11 Jan 2010 23:44:28 +0100

The tag trick worked wonders... Thx..

Regards,
M


On 11. jan. 2010, at 20.56, Martin Weiss wrote:

> 
> <>
> 
> Nick seems to understand your intentions, I honestly do not. That could be
> entirely my problem. Anyway, could you provide the number that you want to
> come out of the calculation in your example?
> 
> 
> HTH
> Martin
> 
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of moleps
> Sent: Montag, 11. Januar 2010 20:32
> To: [email protected]
> Subject: Re: AW: st: AW: generating count and sum variable over two
> different categorical variables
> 
> Thx, Martin. However I need to sum the total number of people in each region
> comprised of from 3-10 different districts. Using 
> 
>> by region yr: egen totpop=total(distr_pop)
> 
> entails summing the district_population the same number of times as the
> number of cases. What I want is to sum the different districts for each year
> for a total regional population.
> 
> 
> 
>  +--------------------------------------------------------------+
>  | pid   distr_~p   district   region     yr   number    totpop |
>  |--------------------------------------------------------------|
>  | 221     440674          3        1   1953        7   2802725 |
>  | 684     440674          3        1   1953        7   2802725 |
>  | 574     158681          6        1   1953        7   2802725 |
>  | 770     440674          3        1   1953        7   2802725 |
>  | 869     440674          3        1   1953        7   2802725 |
>  |--------------------------------------------------------------|
>  | 454     440674          3        1   1953        7   2802725 |
>  | 497     440674          3        1   1953        7   2802725 |
>  | 790     444041          3        1   1954        1    444041 |
>  | 802     112982         13        2   1954        1    112982 |
>  | 767     227937         18        4   1954        1    227937 |
>  |--------------------------------------------------------------|
>  |   .     139172          8        .   1953        0    139172 |
>  +--------------------------------------------------------------+
> 
> 
> //M
> 
> 
> 
> On 11. jan. 2010, at 17.24, Martin Weiss wrote:
> 
>> 
>> <> 
>> 
>> 
>> 
>> *************
>> clear*
>> 
>> input   pid   distr_pop   district   region    yr 
>> 221     440674          3          1   1953 
>> 869     440674          3          1   1953 
>>  .     139172          8          .   1953 
>> 497     440674          3          1   1953 
>> 684     440674          3          1   1953 
>> 574     158681          6          1   1953 
>> 770     440674          3          1   1953 
>> 454     440674          3          1   1953 
>> 767     227937         18          4   1954 
>> 802     112982         13          2   1954 
>> 790     444041          3          1   1954 
>> end
>> 
>> compress
>> 
>> bys region yr: egen number=count(pid)
>> by region yr: egen totpop=total(distr_pop)
>> 
>> li, noo
>> *************
>> 
>> 
>> 
>> HTH
>> Martin
>> 
>> 
>> -----Ursprüngliche Nachricht-----
>> Von: [email protected]
>> [mailto:[email protected]] Im Auftrag von moleps
>> Gesendet: Montag, 11. Januar 2010 17:19
>> An: [email protected]
>> Betreff: Re: st: AW: generating count and sum variable over two different
>> categorical variables
>> 
>> Sorry...
>> 
>> 
>> . list pid distr_pop district region yr in 50/60
>>    | pid   distr_pop   district   region    yr |
>>    |---------------------------------------------|
>> 50. | 221     440674          3          1   1953 |
>> 51. | 869     440674          3          1   1953 |
>> 52. |   .     139172          8          .   1953 |
>> 53. | 497     440674          3          1   1953 |
>> 54. | 684     440674          3          1   1953 |
>>    |---------------------------------------------|
>> 55. | 574     158681          6          1   1953 |
>> 56. | 770     440674          3          1   1953 |
>> 57. | 454     440674          3          1   1953 |
>> 58. | 767     227937         18          4   1954 |
>> 59. | 802     112982         13          2   1954 |
>>    |---------------------------------------------|
>> 60. | 790     444041          3          1   1954 |
>>    +---------------------------------------------+
>> 
>> So what I need to do is generate a variable counting the number of cases
>> from each region for each year and also a variable containing the sum of
> the
>> population for each region for each year. There are between 3 and 10
>> districts in each region. 
>> 
>> Any idea or do I have to program it from scratch?
>> 
>> Regards,
>> M
>> 
>> 
>> 
>> 
>> 
>> On 11. jan. 2010, at 17.06, Martin Weiss wrote:
>> 
>>> 
>>> <> 
>>> 
>>> 
>>> 
>>> As always: Show an excerpt of your data!
>>> 
>>> 
>>> 
>>> HTH
>>> Martin
>>> 
>>> 
>>> -----Ursprüngliche Nachricht-----
>>> Von: [email protected]
>>> [mailto:[email protected]] Im Auftrag von moleps
>>> Gesendet: Montag, 11. Januar 2010 16:58
>>> An: [email protected]
>>> Betreff: st: generating count and sum variable over two different
>>> categorical variables
>>> 
>>> Dear listers,
>>> I´m doing a survival analysis, but also need to present some graphs on a
>>> regional level. In other words my data is setup on an individual level
>> with
>>> categorical variables for year and region. What I need to do is generate
> a
>>> count variable for the cases counted over year AND region. Using the -
>> egen
>>> total- command I´m only able to sum over either year or region. Not both
>> as
>>> far as I understand. Also is there a way to sum over two categories, not
>>> just one.
>>> 
>>> ie my data is setup according to 
>>> 
>>> case year region 
>>> 
>>> and i´d like it setup acording to 
>>> 
>>> case year region #cases/year/region
>>> 
>>> 
>>> Regards,
>>> M
>>> 
>>> 
>>> *
>>> *   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/
>>> 
>>> 
>>> *
>>> *   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/
>> 
>> 
>> *
>> *   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/
>> 
>> 
>> *
>> *   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/
> 
> 
> *
> *   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/
> 
> 
> *
> *   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/


*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index