<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Event study window in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Event-study-window/m-p/444240#M282928</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/198000"&gt;@hkim3677&lt;/a&gt;&amp;nbsp;Does n;t my result match your wanted output? what should your output look like?&lt;/P&gt;</description>
    <pubDate>Fri, 09 Mar 2018 19:51:09 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-03-09T19:51:09Z</dc:date>
    <item>
      <title>Event study window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Event-study-window/m-p/444226#M282925</link>
      <description>&lt;P&gt;Hi SAS masters,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to clean my dataset for -3 and +3 year window.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My current data looks like..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data test;&lt;/P&gt;&lt;P&gt;input ID MANAGER YEAR POST_TURNOVER;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1001 a 1990 0&lt;/P&gt;&lt;P&gt;1001 a 1991 0&lt;/P&gt;&lt;P&gt;1001 a 1992 0&lt;/P&gt;&lt;P&gt;1001 a 1993 0&lt;/P&gt;&lt;P&gt;1001 a 1994 0&lt;/P&gt;&lt;P&gt;1001 a 1995 1&lt;/P&gt;&lt;P&gt;1001 a 1996 1&lt;/P&gt;&lt;P&gt;1001 a 1997&amp;nbsp;1&lt;/P&gt;&lt;P&gt;1001 a 1998 1&lt;/P&gt;&lt;P&gt;1001 a 1999 1&lt;/P&gt;&lt;P&gt;1001 a 1995 0&lt;/P&gt;&lt;P&gt;1001 a 1996 0&lt;/P&gt;&lt;P&gt;1001 a 1997 0&lt;/P&gt;&lt;P&gt;1001 a 1998 0&lt;/P&gt;&lt;P&gt;1001 a 1999 0&lt;/P&gt;&lt;P&gt;1001 a 2000 0&lt;/P&gt;&lt;P&gt;1001&amp;nbsp;b 2000 1&lt;/P&gt;&lt;P&gt;1001 b 2001 1&lt;/P&gt;&lt;P&gt;1001 b 2002 1&lt;/P&gt;&lt;P&gt;1001 b 2003 1&lt;/P&gt;&lt;P&gt;1002 c 1989 0&lt;/P&gt;&lt;P&gt;1002 c 1990 0&lt;/P&gt;&lt;P&gt;1002 c 1991 0&lt;/P&gt;&lt;P&gt;1002 c 1992 0&lt;/P&gt;&lt;P&gt;1002 c 1993 1&lt;/P&gt;&lt;P&gt;1002 c 1994 1&lt;/P&gt;&lt;P&gt;1002 c 1995 1&lt;/P&gt;&lt;P&gt;1002 c 1996 1&lt;/P&gt;&lt;P&gt;1002 c 1997 1&amp;nbsp;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My question here is how I can specify my dataset with -3 and +3 window (excluding the turnover year) for turnovers by ID and Manager.&lt;/P&gt;&lt;P&gt;My data should look like..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ID MANAGER YEAR POST_TURNOVER Turnover&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1001 a 1992 0 0&lt;/P&gt;&lt;P&gt;1001 a 1993 0 0&lt;/P&gt;&lt;P&gt;1001 a 1994 0 0&lt;/P&gt;&lt;P&gt;1001 a 1995 1 1&lt;/P&gt;&lt;P&gt;1001 a 1996 1 0&lt;/P&gt;&lt;P&gt;1001 a 1997&amp;nbsp;1 0&lt;/P&gt;&lt;P&gt;1001 a 1998 1 0&lt;/P&gt;&lt;P&gt;1001 a 1998 0 0&lt;/P&gt;&lt;P&gt;1001 a 1999 0 0&lt;/P&gt;&lt;P&gt;1001 a 2000 0 0&lt;/P&gt;&lt;P&gt;1001&amp;nbsp;b&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;2000 1 1&lt;/P&gt;&lt;P&gt;1001 b 2001 1 0&lt;/P&gt;&lt;P&gt;1001 b 2002 1 0&lt;/P&gt;&lt;P&gt;1001 b 2003 1 0&lt;/P&gt;&lt;P&gt;1002 c 1990 0 0&lt;/P&gt;&lt;P&gt;1002 c 1991 0 0&lt;/P&gt;&lt;P&gt;1002 c 1992 0 0&lt;/P&gt;&lt;P&gt;1002 c 1993 1 1&lt;/P&gt;&lt;P&gt;1002 c 1994 1 0&lt;/P&gt;&lt;P&gt;1002 c 1995 1 0&lt;/P&gt;&lt;P&gt;1002 c 1996 1 0&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 09 Mar 2018 19:28:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Event-study-window/m-p/444226#M282925</guid>
      <dc:creator>hkim3677</dc:creator>
      <dc:date>2018-03-09T19:28:30Z</dc:date>
    </item>
    <item>
      <title>Re: Event study window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Event-study-window/m-p/444230#M282926</link>
      <description>&lt;P&gt;will this help?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data test;

input ID MANAGER YEAR POST_TURNOVER;

datalines;
1001 a 1990 0
1001 a 1991 0
1001 a 1992 0
1001 a 1993 0
1001 a 1994 0
1001 a 1995 1
1001 a 1996 1
1001 a 1997 1
1001 a 1998 1
1001 a 1999 1
1001 a 1995 0
1001 a 1996 0
1001 a 1997 0
1001 a 1998 0
1001 a 1999 0
1001 a 2000 0
1001 b 2000 1
1001 b 2001 1
1001 b 2002 1
1001 b 2003 1
1002 c 1989 0
1002 c 1990 0
1002 c 1991 0
1002 c 1992 0
1002 c 1993 1
1002 c 1994 1
1002 c 1995 1
1002 c 1996 1
1002 c 1997 1 
;

run;


data want;
set test;
by id POST_TURNOVER notsorted;
if first.POST_TURNOVER and POST_TURNOVER then TURNOVER=1;
else TURNOVER=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Mar 2018 19:38:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Event-study-window/m-p/444230#M282926</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-03-09T19:38:59Z</dc:date>
    </item>
    <item>
      <title>Re: Event study window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Event-study-window/m-p/444239#M282927</link>
      <description>&lt;P&gt;How can I specify -3 and +3 event window (excluding the turnover year)?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Mar 2018 19:49:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Event-study-window/m-p/444239#M282927</guid>
      <dc:creator>hkim3677</dc:creator>
      <dc:date>2018-03-09T19:49:57Z</dc:date>
    </item>
    <item>
      <title>Re: Event study window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Event-study-window/m-p/444240#M282928</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/198000"&gt;@hkim3677&lt;/a&gt;&amp;nbsp;Does n;t my result match your wanted output? what should your output look like?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Mar 2018 19:51:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Event-study-window/m-p/444240#M282928</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-03-09T19:51:09Z</dc:date>
    </item>
    <item>
      <title>Re: Event study window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Event-study-window/m-p/444244#M282929</link>
      <description>&lt;P&gt;My data should look like..&lt;/P&gt;&lt;P&gt;ID Manager Year Post_Turnover Turnover&lt;/P&gt;&lt;P&gt;1001 a 1992 0 0&lt;/P&gt;&lt;P&gt;1001 a 1993 0 0&lt;/P&gt;&lt;P&gt;1001 a 1994 0 0&lt;/P&gt;&lt;P&gt;1001 a 1995 1 1&lt;/P&gt;&lt;P&gt;1001 a 1996 1 0&lt;/P&gt;&lt;P&gt;1001 a 1997&amp;nbsp;1 0&lt;/P&gt;&lt;P&gt;1001 a 1998 1 0&lt;/P&gt;&lt;P&gt;1001 a 1998 0 0&lt;/P&gt;&lt;P&gt;1001 a 1999 0 0&lt;/P&gt;&lt;P&gt;1001 a 2000 0 0&lt;/P&gt;&lt;P&gt;1001&amp;nbsp;b&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;2000 1 1&lt;/P&gt;&lt;P&gt;1001 b 2001 1 0&lt;/P&gt;&lt;P&gt;1001 b 2002 1 0&lt;/P&gt;&lt;P&gt;1001 b 2003 1 0&lt;/P&gt;&lt;P&gt;1002 c 1990 0 0&lt;/P&gt;&lt;P&gt;1002 c 1991 0 0&lt;/P&gt;&lt;P&gt;1002 c 1992 0 0&lt;/P&gt;&lt;P&gt;1002 c 1993 1 1&lt;/P&gt;&lt;P&gt;1002 c 1994 1 0&lt;/P&gt;&lt;P&gt;1002 c 1995 1 0&lt;/P&gt;&lt;P&gt;1002 c 1996 1 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see.. I need to restrict my original sample to observations having 3 pre- and post-turnover observations for each manager (excluding the turnover year) or it could be -2 and +2 as well. In other words, the -3 and +3 window allows (-1,+1) (-2,+1) (-3, +1) (-3.+2), etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Mar 2018 20:04:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Event-study-window/m-p/444244#M282929</guid>
      <dc:creator>hkim3677</dc:creator>
      <dc:date>2018-03-09T20:04:24Z</dc:date>
    </item>
    <item>
      <title>Re: Event study window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Event-study-window/m-p/444245#M282930</link>
      <description>&lt;P&gt;Oh My apologies, i haven't got over the hung over from last night. so sorry&lt;/P&gt;</description>
      <pubDate>Fri, 09 Mar 2018 20:08:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Event-study-window/m-p/444245#M282930</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-03-09T20:08:03Z</dc:date>
    </item>
    <item>
      <title>Re: Event study window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Event-study-window/m-p/444247#M282931</link>
      <description>&lt;P&gt;Haha.. its okay.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you help me the code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Mar 2018 20:12:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Event-study-window/m-p/444247#M282931</guid>
      <dc:creator>hkim3677</dc:creator>
      <dc:date>2018-03-09T20:12:22Z</dc:date>
    </item>
    <item>
      <title>Re: Event study window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Event-study-window/m-p/444255#M282932</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/198000"&gt;@hkim3677&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi SAS masters,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to clean my dataset for -3 and +3 year window.&lt;/P&gt;
&lt;HR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;-3 to +3 from what? We need a reference rule. If you wanted all the same years from a single base year, say 1997&lt;/P&gt;
&lt;P&gt;it would be as simple as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if abs(year-1997) le 3;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But obviously you have different years in mind for each manager. What is the rule for selecting the base value for each manager?&lt;/P&gt;
&lt;P&gt;I have to say that with your ID= 1001 and manager = a showing years 1992 to 2000 doesn't jib with any of my simple interpretations of -3 to +3.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Mar 2018 20:27:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Event-study-window/m-p/444255#M282932</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-03-09T20:27:18Z</dc:date>
    </item>
    <item>
      <title>Re: Event study window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Event-study-window/m-p/444256#M282933</link>
      <description>&lt;P&gt;The reference point year is the turnover year.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, I need to retain only -3 and +3 year observations based on the turnover point. Each managers and firm has different turnover year, so I do not have general turnover year. The turnover year varies across firm and manager.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Mar 2018 20:33:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Event-study-window/m-p/444256#M282933</guid>
      <dc:creator>hkim3677</dc:creator>
      <dc:date>2018-03-09T20:33:59Z</dc:date>
    </item>
    <item>
      <title>Re: Event study window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Event-study-window/m-p/444299#M282934</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/198000"&gt;@hkim3677&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First of all, Thank you for the very interesting question&lt;/P&gt;&lt;P&gt;Second of all, My apologies for the lack of attention on my part&lt;/P&gt;&lt;P&gt;Third of all, Sorry for the delay after early vow as I am not feeling well&lt;/P&gt;&lt;P&gt;fourth of all, I would wait for better answers from SAS champs like Art T, K sharp, Tom, mkeintz, chris nz&amp;nbsp; and others&amp;nbsp;&lt;/P&gt;&lt;P&gt;last of all, I will await for your feedback should you require any further changes and in the meantime will have my lunch &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data test;

input ID MANAGER $ YEAR POST_TURNOVER;

datalines;
1001 a 1990 0
1001 a 1991 0
1001 a 1992 0
1001 a 1993 0
1001 a 1994 0
1001 a 1995 1
1001 a 1996 1
1001 a 1997 1
1001 a 1998 1
1001 a 1999 1
1001 a 1995 0
1001 a 1996 0
1001 a 1997 0
1001 a 1998 0
1001 a 1999 0
1001 a 2000 0
1001 b 2000 1
1001 b 2001 1
1001 b 2002 1
1001 b 2003 1
1002 c 1989 0
1002 c 1990 0
1002 c 1991 0
1002 c 1992 0
1002 c 1993 1
1002 c 1994 1
1002 c 1995 1
1002 c 1996 1
1002 c 1997 1 
;

run;


data temp;
set test;
by id POST_TURNOVER notsorted;
if first.POST_TURNOVER and POST_TURNOVER then TURNOVER=1;
else TURNOVER=0;
run;


data want;
drop _:;
if _n_=1 then do;
if 0 then set temp;
dcl hash H () ;
   h.definekey  ("id","year") ;
   h.definedata ("MANAGER","YEAR","POST_TURNOVER","TURNOVER") ;
   h.definedone () ;
end;
set temp end=last;
by id;
retain _year;
if first.id then call missing(_year);
if _count=0 then h.replace();
if turnover=1 then do; 
	_year=year;
	_turnover=turnover;
	do _i=_year-3 to _year;
	if h.find(key:id, key:_i)=0 then output;
	end;
end;
if not turnover and _year then do;
	if _count&amp;lt;=3 then do;
	if _year+1&amp;lt;=year&amp;lt;=_year+3 then _count+1;
	if _count&amp;lt;=3 then output;
	end;
end;
if _count=3 then do; _count=0;call missing(_year);end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Mar 2018 23:18:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Event-study-window/m-p/444299#M282934</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-03-09T23:18:08Z</dc:date>
    </item>
    <item>
      <title>Re: Event study window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Event-study-window/m-p/444438#M282935</link>
      <description>&lt;P&gt;If I understand your question correctly, this is not a complicated task.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do a SET statement with TEST as the object 2 times&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&amp;nbsp;the first time just for turnover years&lt;/LI&gt;
&lt;LI&gt;the second time for all year.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;The SET statement will pass through all the turnover years for a given id first, allowing generation of minyear (minyear=first turnover year minus 3) and maxyear (equal last turnover year +3)&amp;nbsp;.&amp;nbsp; The data step will then pass through ALL years for the same id, where comparison against minyear and maxyear can be tested.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data test;
input ID MANAGER $ YEAR POST_TURNOVER;
datalines;
1001 a 1990 0
1001 a 1991 0
1001 a 1992 0
1001 a 1993 0
1001 a 1994 0
1001 a 1995 1
1001 a 1996 1
1001 a 1997 1
1001 a 1998 1
1001 a 1999 1
1001 a 1995 0
1001 a 1996 0
1001 a 1997 0
1001 a 1998 0
1001 a 1999 0
1001 a 2000 0
1001 b 2000 1
1001 b 2001 1
1001 b 2002 1
1001 b 2003 1
1002 c 1989 0
1002 c 1990 0
1002 c 1991 0
1002 c 1992 0
1002 c 1993 1
1002 c 1994 1
1002 c 1995 1
1002 c 1996 1
1002 c 1997 1 
run;

data want;
  set test (where=(post_turnover=1) in=in1)
      test (in=in2);
  by id manager;
  retain min_year max_year;
  if first.manager then call missing (min_year,max_year);
  if first.manager and in1=1 then min_year=year-3;
  else if in1 then max_year=year+3;

  if in2=1 and  (min_year&amp;lt;=year&amp;lt;=max_year);
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notes&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The RETAIN statement tells SAS to not reset min_year and max_year to missing with every incoming record.&lt;/LI&gt;
&lt;LI&gt;Since all the turnover years are read first, testing on the associated IN1 dummy allows calculation of min_year and max_year.&lt;/LI&gt;
&lt;LI&gt;Then all the years are read (including a re-read of turnover years), allowing a subsetting IF of&amp;nbsp;&amp;nbsp; (min_year&amp;lt;=year&amp;lt;=max_year).&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;The program allows for multi-year event spans (a sequence of post_turnover=1 records), but does not accommodate multiple events separated by non-event years.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Mar 2018 19:39:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Event-study-window/m-p/444438#M282935</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-03-10T19:39:15Z</dc:date>
    </item>
  </channel>
</rss>

