Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Looping within a subset under a certain condition


From   "Gerard Solbrig" <gsolbrig@mail.uni-mannheim.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Looping within a subset under a certain condition
Date   Fri, 28 Sep 2012 22:45:06 +0200

Dear Statalist-Members,

I'm encountering a problem for which I seek your help.

Let me start off with an example from my data (what I want it to look like
in the end), before I explain my particular problem.

firm_id	date		rep	wind_start		wind_end
rep_ins	

firm1		01jan2000	0	.			.
0
firm1		05apr2004	0	.			.
1
firm1		01nov2004	1	05may2004		30may2005
.
firm1		10dec2004	0	.			.
1
firm1		01jan2006	0	.			.
0
firm2		30dec1999	1	03jul1999		27jul2000
.
firm2		05jan2000	1	09jul1999		02aug2000
.
firm2		06jun2000	0	.			.
1

Each firm in my data has a 'firm_id'. Variable 'date' refers to an event
date. The 'rep' dummy indicates the type of event.
I set 'wind_start' and 'wind_end' as period around the event
(-180days,+210days), in case it's a rep = 1 type event.

Now, I would like the 'rep_ins' dummy to indicate (i.e., rep_ins = 1),
whether the date of all other observations of this firm (where rep = 0) lies
within the range determined by 'wind_start' and 'wind_end' (which is
conditional upon the 'rep' dummy).

I've come across looping over observations and tried to design a solution
for this problem based on that, but failed to do so. I assume the solution
also depends on sorting the data in a special way.

Here's the first part of my .do-file:

gen wind_start = date-180 if rep == 1 		
gen wind_end = date+210 if rep == 1
format wind_start %d
format wind_end %d
gsort +cusip6 +date +trandate
gen rep_ins = 0 if rep != 1

I tried to come up with a solution by adding variables 'per_start' and
'per_end' for all rep = 0:

gen per_start = date-180 if rep == 0
gen per_end = date+180 if rep == 0	
format per_start %d
format per_end %d

To mark the period within which the rep = 1 event can lie. Maybe this could
contribute to finding a solution as well.

All input is welcome. Thanks in advance.
Best,
Gerard Solbrig

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index