Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Summing by group of variables


From   "Leonor Saravia" <[email protected]>
To   [email protected]
Subject   Re: st: Summing by group of variables
Date   Tue, 24 Apr 2007 16:31:37 -0400

I really appreciate your responses. Nick, using the commands you tell
me was perfect. Thanks!

Leonor

2007/4/24, n j cox <[email protected]>:
You are confusing & and |, and also two distinct syntaxes
for -egen-.

You could do this

recode region 1/4=1 5 6 7 13=2 8/12=3 , gen(zone)
bysort year industry zone : egen tax_zones = total(tax)

I don't see that -collapse- is the best solution here,
given what else you are likely to be doing.

Nick
[email protected]

Leonor Saravia

I would like to sum the variable "tax" by "year" (2001-2004) and
"industry" (between 31 and 39) if the variable region (between 1 and
13) satisfies some conditions, like: region<=4; region==5 & 6 & 7 & 13
 and if region==8 & 9 &10 & 11 & 12. This way I can create a new
variable: "zones", which is the sum of "tax" payed in an "industry" X
in the "year" 200X considering the range of regions defined before.
I post part of my dataset below.

tax      year      industry  region

300     2001        31         1
230     2001        32          1
300     2002        31          2
110     2002        33          3
240     2003        31         4
260     2004        32         3
10       2004        33         13
 300     2001        31         5
230     2001        32          6
300     2002        31          2
110     2002        33          7
240     2003        31         13
260     2004        32         8
10       2004        33         9
240     2003        31         7
260     2004        32         10
10       2004        33         2
240     2003        31         11
260     2004        32         12
10       2004        33         2

I've tryed using:

bysort year industry: egen tax_zones=sum(tax), by(industry ano) if
region==5 & region==6 & region==7 & region==13

But it didn't work. Please, do you know how can I do this???

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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