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: creating new variable
From
"S.H. Former" <[email protected]>
To
[email protected]
Subject
st: creating new variable
Date
Wed, 12 Oct 2011 18:17:48 +0200
Dear reader,
I have a question regarding the composition of my database. I want to know whether it is possible to incorporate the following variable. I want to create a variable that counts previous observations but only till five years back. Let me explain it using a part my database which looks as follows:
gvkey appyear
1004 1985
1004 2001
1010 1977
1010 1977
1010 1977
1010 1977
1010 1977
1010 1977
1010 1977
1010 1978
1010 1978
1010 1978
1010 1978
1010 1978
1010 1978
1010 1978
1010 1978
1010 1978
1010 1978
1010 1978
1010 1979
1010 1979
1010 1979
1010 1979
1010 1979
1010 1979
1010 1979
1010 1979
1010 1979
Now I want a new variable that counts the number of observations for each Gvkey (so it has to be counted for each Gvkey) where the number of observations is counted until five years back. So the new variable should look like this:
gvkey appyear New Variable Comment
1004 1985 0 no observations before
1004 2001 0 longer than five years ago
1010 1977 0 no observations
1010 1977 0 no observations
1010 1977 0 no observations
1010 1977 0 no observations
1010 1977 0 no observations
1010 1977 0 no observations
1010 1977 0 no observations
1010 1978 7 number of observations in 1977 by Gvkey 1010
1010 1978 7 number of observations in 1977 by Gvkey 1010
1010 1978 7 number of observations in 1977 by Gvkey 1010
1010 1978 7 number of observations in 1977 by Gvkey 1010
1010 1978 7 number of observations in 1977 by Gvkey 1010
1010 1978 7 number of observations in 1977 by Gvkey 1010
1010 1978 7 number of observations in 1977 by Gvkey 1010
1010 1978 7 number of observations in 1977 by Gvkey 1010
1010 1978 7 number of observations in 1977 by Gvkey 1010
1010 1978 7 number of observations in 1977 by Gvkey 1010
1010 1978 7 number of observations in 1977 by Gvkey 1010
1010 1979 18 number of observation in 1977 and 1978 by Gvkey 1010
1010 1979 18 number of observation in 1977 and 1978 by Gvkey 1010
1010 1979 18 number of observation in 1977 and 1978 by Gvkey 1010
1010 1979 18 number of observation in 1977 and 1978 by Gvkey 1010
1010 1979 18 number of observation in 1977 and 1978 by Gvkey 1010
1010 1979 18 number of observation in 1977 and 1978 by Gvkey 1010
1010 1979 18 number of observation in 1977 and 1978 by Gvkey 1010
1010 1979 18 number of observation in 1977 and 1978 by Gvkey 1010
1010 1979 18 number of observation in 1977 and 1978 by Gvkey 1010
Of course, the comment would not have to be included but is to make the problem clear to you! Hope you can help me,
Kind regards,
Sytze
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/