|  | 
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: egen first/lastnm
-egen(newvar) = first(varname)-
(from the egenmore functions) produces missing values when I did not 
expect that behavior. newvar is missing for observations in which 
varname is missing. The same is true for -egen newvar = 
lastnm(varname)-  Is that the behavior I should have expected? In 
contrast, -egen (newvar) = mean(varname) populates newvar even if 
varname is missing. See the example below my signature
Thanks,
Devra
------
Devra Golbe
Dept. of Economics
Hunter College
input n id x
            n         id          x
 1. 1 1 10
 2. 2 1 9
 3. 3 1 11
 4. 4 2 12
 5. 5 2 .
 6. 6 2 11
 7. 7 3 .
 8. 8 3 .
 9. 9 3 10
10. end
. egen y = first(x), by(id)
(3 missing values generated)
egen z = lastnm(x), by(id)
(3 missing values generated)
egen m=mean(x), by(id)
. list
    +------------------------------+
    | n   id    x    y    z      m |
    |------------------------------|
 1. | 1    1   10   10   11     10 |
 2. | 2    1    9   10   11     10 |
 3. | 3    1   11   10   11     10 |
 4. | 4    2   12   12   11   11.5 |
 5. | 5    2    .    .    .   11.5 |
    |------------------------------|
 6. | 6    2   11   12   11   11.5 |
 7. | 7    3    .    .    .     10 |
 8. | 8    3    .    .    .     10 |
 9. | 9    3   10   10   10     10 |
    +------------------------------+
*
*   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/