<?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: how to save the r2 from regressions as a new variable--rolling basis in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/how-to-save-the-r2-from-regressions-as-a-new-variable-rolling/m-p/860640#M82518</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 set sashelp.stocks(keep=stock open high low
rename=(stock=FirmID open=Rit high=Rmt low=Rmt_1));
 by FirmID;
 if first.FirmID then date=0;
 date+1;
 format date date9.;
run;

data all;
 if _n_=1 then do;
  declare hash h(dataset:'have');
  h.definekey('FirmID','date');
  h.definedata(all:'y');
  h.definedone();
 end;
set have;
id+1;
_FirmID=FirmID; _date=date; _Rit=Rit; _Rmt=Rmt; _Rmt_1=Rmt_1;
do i=date+1 to date+90;
  if h.find(key:FirmID,key:i)=0 then output;
end;
format _date date9.;
drop i;
run;

proc reg data=all OUTEST=want(keep=id _FirmID _date _Rit _Rmt _Rmt_1 _RSQ_) rsquare noprint;
by id _FirmID _date _Rit _Rmt _Rmt_1;
model Rit=Rmt Rmt_1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 24 Feb 2023 12:04:42 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2023-02-24T12:04:42Z</dc:date>
    <item>
      <title>how to save the r2 from regressions as a new variable--rolling basis</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-save-the-r2-from-regressions-as-a-new-variable-rolling/m-p/860603#M82517</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a question about how to retrieve the r-square from regressions and store it as a new variable on a rolling basis.&lt;/P&gt;&lt;P&gt;I have daily stock return and daily market return data. For each day, I would like to generate a new variable called sync, and that variable will be the r-square from this regression: R&lt;FONT size="2"&gt;it&amp;nbsp;&lt;FONT size="4"&gt;= &lt;FONT size="3"&gt;R&lt;FONT size="2"&gt;mt + &lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="4"&gt;&lt;FONT size="3"&gt;R&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;mt-1 &lt;FONT size="3"&gt;in&lt;/FONT&gt;&lt;FONT size="4"&gt;&lt;FONT size="3"&gt;&lt;FONT size="2"&gt;&lt;FONT size="3"&gt;&amp;nbsp;the next 90-day window, where Rit is the daily stock return and Rmt is the daily market return. The final dataset would look like this:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT size="4"&gt;&lt;FONT size="3"&gt;&lt;FONT size="2"&gt;&lt;FONT size="3"&gt;FirmID&amp;nbsp; &amp;nbsp; &amp;nbsp;Date&amp;nbsp; &amp;nbsp; &amp;nbsp; Rit&amp;nbsp; &amp;nbsp; &amp;nbsp; Rmt&amp;nbsp; &amp;nbsp; &amp;nbsp; Rmt-1&amp;nbsp; &amp;nbsp; &amp;nbsp; Sync&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT size="4"&gt;&lt;FONT size="3"&gt;&lt;FONT size="2"&gt;&lt;FONT size="3"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/1/23&amp;nbsp; &amp;nbsp; 0.01&amp;nbsp; &amp;nbsp; 0.005&amp;nbsp; &amp;nbsp; 0.006&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a1&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT size="4"&gt;&lt;FONT size="3"&gt;&lt;FONT size="2"&gt;&lt;FONT size="3"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/2/23&amp;nbsp; &amp;nbsp; 0.02&amp;nbsp; &amp;nbsp; 0.006&amp;nbsp; &amp;nbsp; 0.005&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a2&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT size="4"&gt;&lt;FONT size="3"&gt;&lt;FONT size="2"&gt;&lt;FONT size="3"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;&lt;FONT size="4"&gt;&lt;FONT size="3"&gt;&lt;FONT size="2"&gt;&lt;FONT size="3"&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/3/23&amp;nbsp; &amp;nbsp; 0.05&amp;nbsp; &amp;nbsp; 0.003&amp;nbsp; &amp;nbsp; 0.006&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a3&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT size="4"&gt;&lt;FONT size="3"&gt;&lt;FONT size="2"&gt;&lt;FONT size="3"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;...&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT size="4"&gt;&lt;FONT size="3"&gt;&lt;FONT size="2"&gt;&lt;FONT size="3"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;1/1/23&amp;nbsp; &amp;nbsp; 0.06&amp;nbsp; &amp;nbsp; 0.005&amp;nbsp; &amp;nbsp; 0.006&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a4&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT size="4"&gt;&lt;FONT size="3"&gt;&lt;FONT size="2"&gt;&lt;FONT size="3"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;1/2/23&amp;nbsp; &amp;nbsp; 0.07&amp;nbsp; &amp;nbsp; 0.006&amp;nbsp; &amp;nbsp; 0.005&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a5&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT size="4"&gt;&lt;FONT size="3"&gt;&lt;FONT size="2"&gt;&lt;FONT size="3"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;...&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT size="4"&gt;&lt;FONT size="3"&gt;&lt;FONT size="2"&gt;&lt;FONT size="3"&gt;where a1 is the r-square of the regression&amp;nbsp;Rit&amp;nbsp;= Rmt + Rmt-1 from 1/1/23 to 4/1/23&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT size="4"&gt;&lt;FONT size="3"&gt;&lt;FONT size="2"&gt;&lt;FONT size="3"&gt;a2 is the r-square of the&amp;nbsp;regression&amp;nbsp;Rit&amp;nbsp;= Rmt + Rmt-1 from 1/2/23 to 4/2/23&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT size="4"&gt;&lt;FONT size="3"&gt;&lt;FONT size="2"&gt;&lt;FONT size="3"&gt;a3&amp;nbsp;is the r-square of the&amp;nbsp;regression&amp;nbsp;Rit&amp;nbsp;= Rmt + Rmt-1 from 1/3/23 to 4/3/23&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT size="4"&gt;&lt;FONT size="3"&gt;&lt;FONT size="2"&gt;&lt;FONT size="3"&gt;Thank you for your help.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2023 04:06:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-save-the-r2-from-regressions-as-a-new-variable-rolling/m-p/860603#M82517</guid>
      <dc:creator>skyland1991</dc:creator>
      <dc:date>2023-02-24T04:06:04Z</dc:date>
    </item>
    <item>
      <title>Re: how to save the r2 from regressions as a new variable--rolling basis</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-save-the-r2-from-regressions-as-a-new-variable-rolling/m-p/860640#M82518</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 set sashelp.stocks(keep=stock open high low
rename=(stock=FirmID open=Rit high=Rmt low=Rmt_1));
 by FirmID;
 if first.FirmID then date=0;
 date+1;
 format date date9.;
run;

data all;
 if _n_=1 then do;
  declare hash h(dataset:'have');
  h.definekey('FirmID','date');
  h.definedata(all:'y');
  h.definedone();
 end;
set have;
id+1;
_FirmID=FirmID; _date=date; _Rit=Rit; _Rmt=Rmt; _Rmt_1=Rmt_1;
do i=date+1 to date+90;
  if h.find(key:FirmID,key:i)=0 then output;
end;
format _date date9.;
drop i;
run;

proc reg data=all OUTEST=want(keep=id _FirmID _date _Rit _Rmt _Rmt_1 _RSQ_) rsquare noprint;
by id _FirmID _date _Rit _Rmt _Rmt_1;
model Rit=Rmt Rmt_1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Feb 2023 12:04:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-save-the-r2-from-regressions-as-a-new-variable-rolling/m-p/860640#M82518</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-02-24T12:04:42Z</dc:date>
    </item>
    <item>
      <title>Re: how to save the r2 from regressions as a new variable--rolling basis</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-save-the-r2-from-regressions-as-a-new-variable-rolling/m-p/861630#M82543</link>
      <description>&lt;P&gt;Hi Ksharp,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your codes. They work well until the last step. Because of the missing stock return variables, SAS log keeps giving me: "ERROR: No valid observations are found" and the log window will be full. I have to clear the log window every few seconds and because I have millions of obs, it will take me forever. I wonder do you have any suggestions for this? Thank you very much.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;skyland1991&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 00:16:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-save-the-r2-from-regressions-as-a-new-variable-rolling/m-p/861630#M82543</guid>
      <dc:creator>skyland1991</dc:creator>
      <dc:date>2023-03-01T00:16:28Z</dc:date>
    </item>
    <item>
      <title>Re: how to save the r2 from regressions as a new variable--rolling basis</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-save-the-r2-from-regressions-as-a-new-variable-rolling/m-p/861732#M82552</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
You can remove these missing value before 
running my code.
*/
data have;
 set sashelp.stocks(keep=stock open high low
rename=(stock=FirmID open=Rit high=Rmt low=Rmt_1));
 by FirmID;
 if first.FirmID then date=0;
 date+1;
 format date date9.;

 if nmiss(Rit,Rmt,Rmt_1) then delete;  /*&amp;lt;--------*/
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Mar 2023 13:52:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-save-the-r2-from-regressions-as-a-new-variable-rolling/m-p/861732#M82552</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-03-01T13:52:26Z</dc:date>
    </item>
  </channel>
</rss>

