<?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: Triangular Weight for Regression Discontinuity in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Triangular-Weight-for-Regression-Discontinuity/m-p/621307#M19611</link>
    <description>&lt;P&gt;It looks like you want to specify the location of the discontinuity (CENTER) and the scale (BW) and manufacture a triangular weight function. If so, the answer is no, there is no built-in function. As shown, it takes two lines in the DATA step to implement the transformation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS does support using &lt;A href="http://support.sas.com/documentation/cdl/en/procstat/68142/HTML/default/viewer.htm#procstat_univariate_details59.htm" target="_self"&gt;triangular kernels to estimate the density of a distribution&lt;/A&gt;. See the K=TRIANGULAR option on the HISTOGRAM statement of PROC UNIVARIATE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are you trying to accomplish with this kernel weight? For example, if you are trying to model data that have a jump discontinuity, we might be able to suggest better ways,&lt;/P&gt;</description>
    <pubDate>Thu, 30 Jan 2020 20:25:55 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2020-01-30T20:25:55Z</dc:date>
    <item>
      <title>Triangular Weight for Regression Discontinuity</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Triangular-Weight-for-Regression-Discontinuity/m-p/621262#M19607</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to apply a triangular kernel weight for a regression discontinuity design for a given bandwidth.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To Illustrate what I want to accomplish, I generated a fake data set and wrote a macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I was wondering if there was any canned procedure in SAS to accomplish the same thing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sincerely,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bill&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA TEST;&lt;BR /&gt;DO I = 1 TO 1000;&lt;/P&gt;&lt;P&gt;X = RAND("NORMAL", 100, 15);&lt;/P&gt;&lt;P&gt;IF X GT 115 THEN DO;&lt;BR /&gt;Y = X + 15 + RAND("NORMAL", 0 , 3);&lt;BR /&gt;Z = 1;&lt;BR /&gt;END;&lt;BR /&gt;ELSE DO;&lt;BR /&gt;Y = X + RAND("NORMAL", 0 , 3);&lt;BR /&gt;Z = 0;&lt;BR /&gt;END;&lt;/P&gt;&lt;P&gt;OUTPUT;&lt;BR /&gt;END;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;PROC SGPLOT DATA = TEST;&lt;BR /&gt;SCATTER X=X Y=Y / GROUP = Z;&lt;BR /&gt;LINEPARM X=0 Y=0 SLOPE=1 / LINEATTRS=(COLOR = BLUE);&lt;BR /&gt;LINEPARM X=0 Y=15 SLOPE=1 / LINEATTRS=(COLOR = RED);&lt;BR /&gt;REFLINE 115 / AXIS=X LINEATTRS=(PATTERN = DASH);&lt;BR /&gt;XAXIS MIN = 50;&lt;BR /&gt;YAXIS MIN = 40;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MACRO KERNEL_WT(DATA, X, CENTER, BW);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA WTD_DATA;&lt;BR /&gt;SET &amp;amp;DATA;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;IF (&amp;amp;X GT &amp;amp;CENTER - &amp;amp;BW) AND (&amp;amp;X LT &amp;amp;CENTER + &amp;amp;BW) THEN DO;&lt;BR /&gt;KERNEL = (1 - ABS( (&amp;amp;X - &amp;amp;CENTER) / &amp;amp;BW)) ;&lt;BR /&gt;END;&lt;BR /&gt;ELSE KERNEL = 0;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;PROC SQL NOPRINT;&lt;BR /&gt;SELECT SUM(KERNEL) INTO :SUM_KERNEL&lt;BR /&gt;FROM WTD_DATA;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;DATA WTD_DATA;&lt;BR /&gt;SET WTD_DATA;&lt;BR /&gt;WEIGHT = KERNEL / &amp;amp;SUM_KERNEL;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%MEND KERNEL_WT;&lt;/P&gt;&lt;P&gt;%KERNEL_WT(TEST, X, 115, 10);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;PROC SURVEYREG DATA = WTD_DATA;&lt;BR /&gt;MODEL Y = X Z / SOLUTION;&lt;BR /&gt;WEIGHT WEIGHT;&lt;BR /&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2020 18:16:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Triangular-Weight-for-Regression-Discontinuity/m-p/621262#M19607</guid>
      <dc:creator>whs278</dc:creator>
      <dc:date>2020-01-30T18:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: Triangular Weight for Regression Discontinuity</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Triangular-Weight-for-Regression-Discontinuity/m-p/621280#M19609</link>
      <description>&lt;P&gt;Two observations:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Please don't provide all your sas code in uppercase letters.&amp;nbsp; It's harder to read.&amp;nbsp; Just do lowercase, with occasional selective use of uppercase.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;You can do the job of the macro KERNEL in a single data step,&amp;nbsp; as in&amp;nbsp; (untested):&lt;/LI&gt;
&lt;/OL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO KERNEL_WT(data,x,center,bw);
  data wtd_data;
    set &amp;amp;data  (in=firstpass)
        &amp;amp;data  (in=secondpass);
    if -&amp;amp;bw &amp;lt; (&amp;amp;x-&amp;amp;center) &amp;lt; &amp;amp;bw then  kernel = (1 - abs( (&amp;amp;x - &amp;amp;center) / &amp;amp;bw)) ;
    else kernel=0;

    if firstpass=1 then sum_kernel+kernel;
    if secondpass=1;
    weight=kernel/ sum_kernel;
run;
%MEND KERNEL_WT;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note the SET statement reads the dataset twice.&amp;nbsp; The first time (firstpass=1) to generate SUM_KERNEL, and the second time to generate the weights and output the results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2020 19:12:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Triangular-Weight-for-Regression-Discontinuity/m-p/621280#M19609</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-01-30T19:12:17Z</dc:date>
    </item>
    <item>
      <title>Re: Triangular Weight for Regression Discontinuity</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Triangular-Weight-for-Regression-Discontinuity/m-p/621288#M19610</link>
      <description>Thank you for the tip. This is a definite improvement over my original macro.&lt;BR /&gt;&lt;BR /&gt;However, I was still wondering if there is a triangular kernel procedure in SAS already available? I am currently working on regression discontinuity project and I want to add more weight to observations close to the threshold.</description>
      <pubDate>Thu, 30 Jan 2020 19:28:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Triangular-Weight-for-Regression-Discontinuity/m-p/621288#M19610</guid>
      <dc:creator>whs278</dc:creator>
      <dc:date>2020-01-30T19:28:02Z</dc:date>
    </item>
    <item>
      <title>Re: Triangular Weight for Regression Discontinuity</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Triangular-Weight-for-Regression-Discontinuity/m-p/621307#M19611</link>
      <description>&lt;P&gt;It looks like you want to specify the location of the discontinuity (CENTER) and the scale (BW) and manufacture a triangular weight function. If so, the answer is no, there is no built-in function. As shown, it takes two lines in the DATA step to implement the transformation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS does support using &lt;A href="http://support.sas.com/documentation/cdl/en/procstat/68142/HTML/default/viewer.htm#procstat_univariate_details59.htm" target="_self"&gt;triangular kernels to estimate the density of a distribution&lt;/A&gt;. See the K=TRIANGULAR option on the HISTOGRAM statement of PROC UNIVARIATE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are you trying to accomplish with this kernel weight? For example, if you are trying to model data that have a jump discontinuity, we might be able to suggest better ways,&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2020 20:25:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Triangular-Weight-for-Regression-Discontinuity/m-p/621307#M19611</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-01-30T20:25:55Z</dc:date>
    </item>
    <item>
      <title>Re: Triangular Weight for Regression Discontinuity</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Triangular-Weight-for-Regression-Discontinuity/m-p/621321#M19612</link>
      <description>Hi Rick,&lt;BR /&gt;&lt;BR /&gt;Thanks for the response. I am trying to estimate a treatment effect at the discontinuity using local linear regression. I wanted to use a triangular kernel function to weight observations closer to the discontinuity higher than those farther away. My concern is that observations farther away from the threshold may be biasing the estimate.&lt;BR /&gt;&lt;BR /&gt;What I have been trying so far is using the code above to create a variable containing weights in the data set. Then I have been using PROC SURVEYREG with the WEIGHT Statement using only observations within the bandwidth.</description>
      <pubDate>Thu, 30 Jan 2020 22:06:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Triangular-Weight-for-Regression-Discontinuity/m-p/621321#M19612</guid>
      <dc:creator>whs278</dc:creator>
      <dc:date>2020-01-30T22:06:52Z</dc:date>
    </item>
    <item>
      <title>Re: Triangular Weight for Regression Discontinuity</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Triangular-Weight-for-Regression-Discontinuity/m-p/621329#M19613</link>
      <description>&lt;P&gt;I see. You are trying to perform "kernel regression", which is a form of local regression.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your current implementation of the technique will only give you the local regression at a single location.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See the article &lt;A href="https://blogs.sas.com/content/iml/2018/08/29/kernel-regression-in-sas.html" target="_self"&gt;"Kernel regression in SAS"&amp;nbsp;&lt;/A&gt;for an implementation. However, a better method is to use &lt;A href="https://blogs.sas.com/content/iml/2016/10/17/what-is-loess-regression.html" target="_self"&gt;loess regression ,&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;which is available by using PROC LOESS. Here is a loess fit for your data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sgplot data=TEST;
loess X=X Y=Y;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Jan 2020 22:29:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Triangular-Weight-for-Regression-Discontinuity/m-p/621329#M19613</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-01-30T22:29:42Z</dc:date>
    </item>
  </channel>
</rss>

