This is very inelegant and will be very slow, as it proceeds
observation by observation, but it should do the trick.
You may want to change the definitition of temp2 to read "<="
depending on how you want to deal with entry and exits occuring in the
same time period.
gen temp1=(size==6)
gen new=.
local n=_N
qui forvalues i = 1/ `n' {
capture drop temp2
capture drop temp3
gen temp2=1 if entry<exit[`i']
egen temp3=sum(temp1) if temp2==1
replace new=temp3 in `i'
}
--Carole
_________________________________
Carole J. Wilson
University of Texas at Dallas
School of Economic, Political,
and Policy Sciences
Phone: 972.883.4957
Fax: 972.883.6571
[email protected]
http://www.utdallas.edu/~cjwilson
__________________________________
On 3/26/07, [email protected] <[email protected]> wrote:
Dear Statalist members,
I have a question regarding the definition of a new variable in a data
set. I would like to define this new variable in the way that it will
tell me how many subjects with a specific characteristic exist at a
specific time. For example: Suggesting a simplified data set of nine
subjects with information regarding their market-entry, market-exit, and
size. In this case, I would like to know how many subjects with the size
6 were in the market at the same time with each other subject.
Example:
ID Market-Entry Market-Exit Size
New_Variable
1 10 98 1
1
2 15 80 1
0
3 30 110 1
2
4 41 97 1
1
5 76 85 1
1
6 77 218 2
2
7 85 220 3
2
8 82 118 6
2
9 99 218 6
2
For ID1, for example, subject 8 entered at time 82, while ID1
markets-exist is 98. The other subject with size 6 is ID9. But ID9
entered the market after the market-exist of ID1. So the variable should
hold the value 1 (One subject with size 6 was present in the market at
the same time as ID1). Regarding subject ID2, ID8 and ID 9 entered after
the market-exit of ID2, so the new variable should hold the value 0. For
ID3, the new variable should hold the value 2, because both subjects
with the size 6 were present in the market at the same time than ID3,
and so on.
I really appreciate for any help and suggestions.
Simon
*
* 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/
*
* 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/