<?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: Diff in diff in panel data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Diff-in-diff-in-panel-data/m-p/391350#M277663</link>
    <description>&lt;P&gt;I assume (a) you have annual records for each ID, (b) every ID has a displacement, and (c) &amp;nbsp;the year of displacement is always the last record for a given ID.&amp;nbsp; Then this will work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;FONT color="#000080" face="Sasfont"&gt;&lt;STRONG&gt;&lt;CODE class=" language-sas"&gt;data want;

  do N_years=1 by 1 until (last.id);
    set have ;
    by id notsorted;
    sal_T_minus_1=lag(salary);
    sal_T_minus_2=lag2(salary);
    sal_T_minus_3=lag3(salary);
    sal_T_minus_4=lag4(salary);
  end;

  array sal{4} sal_T_minus_1-sal_T_minus_4;

  if N_years&amp;lt;=4 then do N=N_years to 4;
    sal{N}=.;
  end;
  drop N;

run;&lt;/CODE&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;This program writes out only 1 record per ID, since your regression only needs the data you create for the last within-id record.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;If an ID is short (has few records) then some of the lagged salary values will be contaminated by the prior ID.&amp;nbsp; For instance, if you have only&amp;nbsp;2 years, then the 3 year lag and 4 year lag will be contaminated.&amp;nbsp; This is corrected in the "if N_years&amp;lt;4 then do N=N_years+1 to 4" loop&amp;nbsp;(and yes, it is possible to use the variable N_years not only as the loop index, but also a bound on the index).&lt;/LI&gt;
&lt;LI&gt;If you want more than 4 pre-displaced years then
&lt;OL&gt;
&lt;LI&gt;add LAG statements in the first DO loop&lt;/LI&gt;
&lt;LI&gt;increase the size of the SAL array&lt;/LI&gt;
&lt;LI&gt;Modify the bounds in the second DO loop&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;LI&gt;In addition to salary history, you also have an additional variable - N_years - which is a count of annual records for each ID.&lt;/LI&gt;
&lt;/OL&gt;</description>
    <pubDate>Tue, 29 Aug 2017 00:18:54 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2017-08-29T00:18:54Z</dc:date>
    <item>
      <title>Diff in diff in panel data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Diff-in-diff-in-panel-data/m-p/391299#M277662</link>
      <description>&lt;P&gt;Hi everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a database with workers (id) in firms (worker x id), their salary, the year of the observation, as well as a variable displaced equal to one if they will&amp;nbsp;be displaced from the firm&amp;nbsp;the year after&amp;nbsp;(if displaced=1 in 2002, the worker is displaced from the firm in 2003. Displaced has been created based on the disappearance of the worker from the panel. The salary in 2003 at year &lt;EM&gt;t&lt;/EM&gt; will be thus of 0).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;id &amp;nbsp; &amp;nbsp; &amp;nbsp; firm x id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; displaced &amp;nbsp; &amp;nbsp; year &amp;nbsp; &amp;nbsp; &amp;nbsp; salary &amp;nbsp; Salary t-1 &amp;nbsp; &amp;nbsp; Salary t-2&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2002 &amp;nbsp; &amp;nbsp; &amp;nbsp; 2000 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1500 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2000 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 22 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2002 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;560 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; . &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 22 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2003 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;580 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; . &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 22 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2004 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 600 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;580 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 560&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to do a diff in diff regression over several years to &lt;STRONG&gt;estimate the effect of displacement on revenue&lt;/STRONG&gt;. The problem is I want to take &lt;EM&gt;t&lt;/EM&gt;&amp;nbsp;(salary at displacement year) as the dependent variable&amp;nbsp;of the regression, but also do the regression on passed years' salary to see the influence of displacement at year&lt;EM&gt; t&lt;/EM&gt; on revenue at year&lt;EM&gt;&amp;nbsp;t-1&lt;/EM&gt; for example. I thus have to create, for each individual displaced &amp;nbsp;at year &lt;EM&gt;t&lt;/EM&gt; with the &lt;EM&gt;salary t&lt;/EM&gt;, a variable in the same row indicating the revenu in&lt;EM&gt; t&lt;/EM&gt;-1, &lt;EM&gt;t&lt;/EM&gt;-2, &lt;EM&gt;t&lt;/EM&gt;-3 etc. &lt;STRONG&gt;Salary t-1 and Salary t-2 in the table above are the variables I look for.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you know if it is at least possible to do something like this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would be very grateful for help!!!&lt;/P&gt;&lt;P&gt;Thank you in advance,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Eugénie&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;</description>
      <pubDate>Mon, 28 Aug 2017 18:37:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Diff-in-diff-in-panel-data/m-p/391299#M277662</guid>
      <dc:creator>eugenia67</dc:creator>
      <dc:date>2017-08-28T18:37:22Z</dc:date>
    </item>
    <item>
      <title>Re: Diff in diff in panel data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Diff-in-diff-in-panel-data/m-p/391350#M277663</link>
      <description>&lt;P&gt;I assume (a) you have annual records for each ID, (b) every ID has a displacement, and (c) &amp;nbsp;the year of displacement is always the last record for a given ID.&amp;nbsp; Then this will work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;FONT color="#000080" face="Sasfont"&gt;&lt;STRONG&gt;&lt;CODE class=" language-sas"&gt;data want;

  do N_years=1 by 1 until (last.id);
    set have ;
    by id notsorted;
    sal_T_minus_1=lag(salary);
    sal_T_minus_2=lag2(salary);
    sal_T_minus_3=lag3(salary);
    sal_T_minus_4=lag4(salary);
  end;

  array sal{4} sal_T_minus_1-sal_T_minus_4;

  if N_years&amp;lt;=4 then do N=N_years to 4;
    sal{N}=.;
  end;
  drop N;

run;&lt;/CODE&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;This program writes out only 1 record per ID, since your regression only needs the data you create for the last within-id record.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;If an ID is short (has few records) then some of the lagged salary values will be contaminated by the prior ID.&amp;nbsp; For instance, if you have only&amp;nbsp;2 years, then the 3 year lag and 4 year lag will be contaminated.&amp;nbsp; This is corrected in the "if N_years&amp;lt;4 then do N=N_years+1 to 4" loop&amp;nbsp;(and yes, it is possible to use the variable N_years not only as the loop index, but also a bound on the index).&lt;/LI&gt;
&lt;LI&gt;If you want more than 4 pre-displaced years then
&lt;OL&gt;
&lt;LI&gt;add LAG statements in the first DO loop&lt;/LI&gt;
&lt;LI&gt;increase the size of the SAL array&lt;/LI&gt;
&lt;LI&gt;Modify the bounds in the second DO loop&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;LI&gt;In addition to salary history, you also have an additional variable - N_years - which is a count of annual records for each ID.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Tue, 29 Aug 2017 00:18:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Diff-in-diff-in-panel-data/m-p/391350#M277663</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-08-29T00:18:54Z</dc:date>
    </item>
    <item>
      <title>Re: Diff in diff in panel data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Diff-in-diff-in-panel-data/m-p/391394#M277664</link>
      <description>Hi Mark ! Thank you so much, I will try this! Actually the displacement year is not the last record of each id infortunetaly, because an id can find a work in a new firm the next year or even several years after and reappear in the panel .. nevertheless I can use id x firm identifier as if a worker is displaced the code id x identifier will appear for the last time. I just have to check if this id is in the firm for at lest 4 years to do that ..&lt;BR /&gt;&lt;BR /&gt;I already used the id x firm code to identify displaced id that are reemployed the next year. I compared the last.idxfirm year to the last.id year and if these two are different in two year (the first year being the displacement year) then the worker is reemplyed. Maybe this info will help me!&lt;BR /&gt;&lt;BR /&gt;I will also have to do the same exercise for salary_T_plus_1 salaryT_plus_2 etc until 4 (the year when the id does not appear in the record because he is not employed will be marked as "0 salary".. I have thus to replace lag by what ?&lt;BR /&gt;&lt;BR /&gt;Thank you so much !&lt;BR /&gt;Eugénie</description>
      <pubDate>Tue, 29 Aug 2017 06:19:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Diff-in-diff-in-panel-data/m-p/391394#M277664</guid>
      <dc:creator>eugenia67</dc:creator>
      <dc:date>2017-08-29T06:19:04Z</dc:date>
    </item>
  </channel>
</rss>

