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]

st: -egen total()- function and indexing within the -if- condition


From   A Loumiotis <[email protected]>
To   [email protected]
Subject   st: -egen total()- function and indexing within the -if- condition
Date   Mon, 15 Apr 2013 14:03:35 +0300

Hi,

I thought that the index number in the -if- condition is reseted to 1
at the beginning of every -by- group when generating a variable using
the -egen total()- function.  It seems that this is not the case
though as the example below demonstrates:

********
clear
input int i j x
1 1 10
1 2 0
1 3 15
2 1 15
2 2 1
2 3 20
end
bys i:gen s2x=sum(x) if x[2]==1 & inlist(j,1,3)
bys i:egen t2x=total(x) if x[2]==1 & inlist(j,1,3)
bys i:gen s5x=sum(x) if x[5]==1 & inlist(j,1,3)
bys i:egen t5x=total(x) if x[5]==1 & inlist(j,1,3)
li, sepby(i)

     +------------------------------------+
     | i   j    x   s2x   t2x   s5x   t5x |
     |------------------------------------|
  1. | 1   1   10     .     .     .    25 |
  2. | 1   2    0     .     .     .     . |
  3. | 1   3   15     .     .     .    25 |
     |------------------------------------|
  4. | 2   1   15    15     .     .    35 |
  5. | 2   2    1     .     .     .     . |
  6. | 2   3   20    35     .     .    35 |
     +------------------------------------+

*********

I expected that t2x and t5x would be missing whenever s2x and s5x is
missing but it is not.  The results of the -sum()- function seems
logical to me given the -if- condition but not the results of the
-total()- function.  Is this the normal behavior of the -total()-
function or is this a bug?

Best,
Antonis
*
*   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