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: Create a new variable based on the current observation and values of other observations in the same group
From
Huanhuan Shi <[email protected]>
To
[email protected]
Subject
st: Create a new variable based on the current observation and values of other observations in the same group
Date
Sun, 13 Oct 2013 18:57:35 -0400
Dear Statalist,
I have a problem which is similar to but different from this post.
http://www.stata.com/support/faqs/data-management/creating-variables-recording-properties/
I tried to modify the code suggested by Nicholas J. Cox but can not
figure it out. Hope I can get help from you.
The problem I am facing is as follows:
First, the data structure is shown below. I have family groups and
individuals in each family group.
family person sex age
1. 1 1 1 36
2. 1 2 1 16
3. 1 3 1 14
4. 2 1 0 45
5. 2 2 1 42
6. 2 3 0 14
7. 2 4 1 12
8. 2 5 0 10
9. 3 1 0 39
10. 3 2 1 36
11. 3 3 0 11
12. 3 4 1 9
13. 3 5 1 7
14. 3 6 1 3
What I want to do is to create a new variable "count" that count the
number of individual that sex is 1 and10 years younger than the
person within the same family. So the result should be like:
family person sex age count
1. 1 1 1 36 2
2. 1 2 1 16 0
3. 1 3 1 14 0
4. 2 1 0 45 1
5. 2 2 1 42 1
6. 2 3 0 14 0
7. 2 4 1 12 0
8. 2 5 0 10 0
9. 3 1 0 39 3
10. 3 2 1 36 3
11. 3 3 0 11 0
12. 3 4 1 9 0
13. 3 5 1 7 0
14. 3 6 1 3 0
Thank you so much!!
Huanhuan
*
* 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/