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: RE: Create a new variable based on the current observation and values of other observations in the same group


From   Red Owl <[email protected]>
To   <[email protected]>
Subject   st: RE: Create a new variable based on the current observation and values of other observations in the same group
Date   Sun, 13 Oct 2013 19:22:43 -0400

Huanhuan,

Perhaps the following will do what you want:

clear
input byte(family person sex age)
 1          1          1         36
 1          2          1         16
 1          3          1         14
 2          1          0         45
 2          2          1         42
 2          3          0         14
 2          4          1         12
 2          5          0         10
 3          1          0         39
 3          2          1         36
 3          3          0         11
 3          4          1          9
 3          5          1          7
 3          6          1          3
 end

bysort family: egen minage=min(age)
bysort family: gen flag = sex==1 & (age-minage)<=10
bysort family: egen count = total(flag)

list if sex==1, noobs sepby(family)


Red Owl
[email protected]
*
*   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