<?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: Creating the second lag in a panel data set in SAS Forecasting and Econometrics</title>
    <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Creating-the-second-lag-in-a-panel-data-set/m-p/436441#M3000</link>
    <description>&lt;P&gt;The documentation has examples, with one exactly calculating lag1 and lag2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=etsug&amp;amp;docsetVersion=14.3&amp;amp;docsetTarget=etsug_expand_examples04.htm&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=etsug&amp;amp;docsetVersion=14.3&amp;amp;docsetTarget=etsug_expand_examples04.htm&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 12 Feb 2018 20:29:49 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-02-12T20:29:49Z</dc:date>
    <item>
      <title>Creating the second lag in a panel data set</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Creating-the-second-lag-in-a-panel-data-set/m-p/436061#M2994</link>
      <description>&lt;P&gt;I have panel data, and I am trying to create&amp;nbsp;lags. The code below seems to be generating the desired results for the first lag of the variable of interest.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=Pooled_Panel;&lt;BR /&gt;by Country Year;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data Pooled_Panel_lags;&lt;BR /&gt;set Pooled_Panel;&lt;BR /&gt;by Country Year;&lt;BR /&gt;Lag_EFWS=Lag(EFWS);&lt;BR /&gt;If First.Country then do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;Lag_EFWS=.;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;My question is this.&amp;nbsp; How do I do this for the second lag?&amp;nbsp; I know to use Lag2(variable), but&amp;nbsp;what type of if-then statement do I need here?&amp;nbsp; I don't want the second lag to be the value two rows before&amp;nbsp;if that value corresponds to another country.&amp;nbsp; I'm using SAS 9.4.&lt;/P&gt;</description>
      <pubDate>Sun, 11 Feb 2018 04:06:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Creating-the-second-lag-in-a-panel-data-set/m-p/436061#M2994</guid>
      <dc:creator>bssturgi</dc:creator>
      <dc:date>2018-02-11T04:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: Creating the second lag in a panel data set</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Creating-the-second-lag-in-a-panel-data-set/m-p/436067#M2995</link>
      <description>&lt;P&gt;Do you have SAS/ETS? If so, you can do this a bit more easily with the convert statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you don't, you're stuck with a counter. Create a counter variable using RETAIN and then delete any less than what you need.&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;PRE&gt;&lt;CODE class=" language-sas"&gt;data Pooled_Panel_lags;
set Pooled_Panel;
by Country Year;

Lag_EFWS  = Lag(EFWS);
Lag_EFWS2 = Lag2(EFWS);
 
If First.Country then counter=0;

counter+1;

if counter &amp;lt;= 1 then call missing(lag_efws, lag_efws2);
if counter &amp;lt;= 2 then call missing(lag_efws2);



run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't test it, but this may work as well, make sure to only Keep what you need in each data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
merge pooled_panel
           pooled_panel (firstobs=2 rename = (efws = lag_efws) keep=(PUT VARIABLE LIST HERE))
           pooled_panel (firstobs=3) rename = (efws = lag_efws2) keep=(PUT VARIABLE LIST HERE));

by country;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Feb 2018 04:59:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Creating-the-second-lag-in-a-panel-data-set/m-p/436067#M2995</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-11T04:59:53Z</dc:date>
    </item>
    <item>
      <title>Re: Creating the second lag in a panel data set</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Creating-the-second-lag-in-a-panel-data-set/m-p/436437#M2999</link>
      <description>&lt;P&gt;Thank you!&amp;nbsp; The code you provided with the counter has done the trick.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't have SAS/ETS, but I think one of my colleagues may have at, and I may get it in the future.&amp;nbsp; Could you tell me how I would do this with the convert statement?&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 20:11:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Creating-the-second-lag-in-a-panel-data-set/m-p/436437#M2999</guid>
      <dc:creator>bssturgi</dc:creator>
      <dc:date>2018-02-12T20:11:16Z</dc:date>
    </item>
    <item>
      <title>Re: Creating the second lag in a panel data set</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Creating-the-second-lag-in-a-panel-data-set/m-p/436441#M3000</link>
      <description>&lt;P&gt;The documentation has examples, with one exactly calculating lag1 and lag2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=etsug&amp;amp;docsetVersion=14.3&amp;amp;docsetTarget=etsug_expand_examples04.htm&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=etsug&amp;amp;docsetVersion=14.3&amp;amp;docsetTarget=etsug_expand_examples04.htm&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 20:29:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Creating-the-second-lag-in-a-panel-data-set/m-p/436441#M3000</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-12T20:29:49Z</dc:date>
    </item>
  </channel>
</rss>

