<?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 Lagging variables in unbalanced panel in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Lagging-variables-in-unbalanced-panel/m-p/394657#M66388</link>
    <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have an UNBALANCED PANEL &amp;nbsp;of clients (i.e. not all clients are present on every year) for four years (2010-2013). I would like to calculate the change in costs over the years. The problem is that when I lag the variable "costs", SAS lags over all client numbers (i.e. 2013 of client1 will become 2010 for client2). How do I prevent this from happening?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't just take out year=2010, because for some clients 2011 was the first year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I have so far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/SPAN&gt; costchange;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s2"&gt;set&lt;/SPAN&gt; sample;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s2"&gt;by&lt;/SPAN&gt;&amp;nbsp;cient;&lt;/P&gt;&lt;P class="p1"&gt;lcost=lag(cost);&lt;/P&gt;&lt;P class="p1"&gt;cost_score = (cost - lcost)/lcost;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s2"&gt;where&lt;/SPAN&gt; treated=&lt;SPAN class="s3"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;;&lt;/P&gt;&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;SPAN class="s4"&gt;;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 11 Sep 2017 13:03:03 GMT</pubDate>
    <dc:creator>GKati</dc:creator>
    <dc:date>2017-09-11T13:03:03Z</dc:date>
    <item>
      <title>Lagging variables in unbalanced panel</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lagging-variables-in-unbalanced-panel/m-p/394657#M66388</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have an UNBALANCED PANEL &amp;nbsp;of clients (i.e. not all clients are present on every year) for four years (2010-2013). I would like to calculate the change in costs over the years. The problem is that when I lag the variable "costs", SAS lags over all client numbers (i.e. 2013 of client1 will become 2010 for client2). How do I prevent this from happening?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't just take out year=2010, because for some clients 2011 was the first year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I have so far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/SPAN&gt; costchange;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s2"&gt;set&lt;/SPAN&gt; sample;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s2"&gt;by&lt;/SPAN&gt;&amp;nbsp;cient;&lt;/P&gt;&lt;P class="p1"&gt;lcost=lag(cost);&lt;/P&gt;&lt;P class="p1"&gt;cost_score = (cost - lcost)/lcost;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s2"&gt;where&lt;/SPAN&gt; treated=&lt;SPAN class="s3"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;;&lt;/P&gt;&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;SPAN class="s4"&gt;;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2017 13:03:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lagging-variables-in-unbalanced-panel/m-p/394657#M66388</guid>
      <dc:creator>GKati</dc:creator>
      <dc:date>2017-09-11T13:03:03Z</dc:date>
    </item>
    <item>
      <title>Re: Lagging variables in unbalanced panel</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lagging-variables-in-unbalanced-panel/m-p/394660#M66389</link>
      <description>&lt;P&gt;As always, some test data in the form of a datastep would help clarify what you mean. &amp;nbsp;At a guess, maybe use retain'd variables and set them once per group, then when missing use the retained variable.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2017 13:15:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lagging-variables-in-unbalanced-panel/m-p/394660#M66389</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-09-11T13:15:37Z</dc:date>
    </item>
    <item>
      <title>Re: Lagging variables in unbalanced panel</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lagging-variables-in-unbalanced-panel/m-p/394666#M66390</link>
      <description>&lt;P&gt;When using LAG, it's important to make sure it executes on every observation.&amp;nbsp; You're doing that ... so far so good.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The trick is to wipe out the value for observations that begin a new CLIENT.&amp;nbsp; So:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/SPAN&gt; costchange;&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="s2"&gt;set&lt;/SPAN&gt; sample;&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="s2"&gt;by&lt;/SPAN&gt;&amp;nbsp;cient;&lt;/P&gt;
&lt;P class="p1"&gt;lcost=lag(cost);&lt;/P&gt;
&lt;P class="p1"&gt;if first.client then lcost = . ;&lt;/P&gt;
&lt;P class="p1"&gt;cost_score = (cost - lcost)/lcost;&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="s2"&gt;where&lt;/SPAN&gt; treated=&lt;SPAN class="s3"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;;&lt;/P&gt;
&lt;P class="p1"&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2017 13:22:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lagging-variables-in-unbalanced-panel/m-p/394666#M66390</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-09-11T13:22:38Z</dc:date>
    </item>
    <item>
      <title>Re: Lagging variables in unbalanced panel</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lagging-variables-in-unbalanced-panel/m-p/394668#M66391</link>
      <description>&lt;P&gt;Perfect! Just what I was looking for.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2017 13:23:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lagging-variables-in-unbalanced-panel/m-p/394668#M66391</guid>
      <dc:creator>GKati</dc:creator>
      <dc:date>2017-09-11T13:23:45Z</dc:date>
    </item>
  </channel>
</rss>

