<?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: Restrict a coefficient in regression analysis with SAS/IML in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Restrict-a-coefficient-in-regression-analysis-with-SAS-IML/m-p/181733#M1814</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sounds good.&amp;nbsp; Try my formula on a simple example and compare it with the PROC REG results to see if it work. Best wishes.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 16 Apr 2014 15:17:23 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2014-04-16T15:17:23Z</dc:date>
    <item>
      <title>Restrict a coefficient in regression analysis with SAS/IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Restrict-a-coefficient-in-regression-analysis-with-SAS-IML/m-p/181730#M1811</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am conducting a bootstrap exercise for my research. So I have to conduct a replication for each replication. Due to model restrictions, I have to constrain the coefficient of the one of the two explanatory variables to an also simulated variable. I couldn't do that with proc reg since the restriction must be a variable defined in the afore model statement. I am trying to do it within&amp;nbsp; IML with a loop. The problem is how to define the restriction in the beta estimation. Below is my macro code. I want to set the coefficient estimate R_BETA equal to the value of Ret_var for replication.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro reg_loop;&lt;/P&gt;&lt;P&gt;%do j=1 %to 2500;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA Cross;&lt;/P&gt;&lt;P&gt;set Mcb.Cross;&lt;/P&gt;&lt;P&gt;if replicate=&amp;amp;j;&lt;/P&gt;&lt;P&gt;Data Variance;&lt;/P&gt;&lt;P&gt;set Mcb.Variance&lt;/P&gt;&lt;P&gt;if replicate=&amp;amp;j;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC IML;&lt;/P&gt;&lt;P&gt;use Cross;&lt;/P&gt;&lt;P&gt;read all var {CF_BETA R_BETA} into X;&lt;/P&gt;&lt;P&gt;read all var {eret_mean} into Y;&lt;/P&gt;&lt;P&gt;use Variance;&lt;/P&gt;&lt;P&gt;real all var{Ret_var} into Restr;&lt;/P&gt;&lt;P&gt;/*************************************************************************************&lt;/P&gt;&lt;P&gt;*&amp;nbsp;&amp;nbsp; I&amp;nbsp; believe I need a small ``trick'' here.&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;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *&lt;/P&gt;&lt;P&gt;*************************************************************************************/&lt;/P&gt;&lt;P&gt;n=nrow(X);&lt;/P&gt;&lt;P&gt;k=ncol(X);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;X=J(n,1,1)||X;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;C=inv(X`*X);&lt;/P&gt;&lt;P&gt;B_Hat=C*X`*Y;&lt;/P&gt;&lt;P&gt;/************************************************************************************/&lt;/P&gt;&lt;P&gt;SSE=y`*y-B_Hat`*X`*Y;&lt;/P&gt;&lt;P&gt;DFE=n-k-1;&lt;/P&gt;&lt;P&gt;MSE=SSE/DFE;&lt;/P&gt;&lt;P&gt;Mean_Y=Sum(Y)/n;&lt;/P&gt;&lt;P&gt;SSR=B_Hat`*X`*Y-n*Mean_Y**2;&lt;/P&gt;&lt;P&gt;MSR=SSR/k;&lt;/P&gt;&lt;P&gt;SST=SSR+SSE;&lt;/P&gt;&lt;P&gt;F=MSR/MSE;&lt;/P&gt;&lt;P&gt;SE=SQRT(vecdiag(C)#MSE);&lt;/P&gt;&lt;P&gt;T=B_Hat/SE;&lt;/P&gt;&lt;P&gt;PROBT=2*(1-CDF('T', ABS(T), DFE));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;B_Hat = B_Hat`;&lt;/P&gt;&lt;P&gt;SE = SE`;&lt;/P&gt;&lt;P&gt;T = T`;&lt;/P&gt;&lt;P&gt;PROBT = PROBT`;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ANOVA_Table=(k||SSR||MSR||F||DFE||SSE||MSE);&lt;/P&gt;&lt;P&gt;STATS_Table=B_Hat||SE||T||PROBT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;create x from ANOVA_Table;&lt;/P&gt;&lt;P&gt;append from ANOVA_Table;&lt;/P&gt;&lt;P&gt;create y from STATS_Table;&lt;/P&gt;&lt;P&gt;append from STATS_Table;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data x;&lt;/P&gt;&lt;P&gt;set x;&lt;/P&gt;&lt;P&gt;replicate=&amp;amp;j;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data y;&lt;/P&gt;&lt;P&gt;set y;&lt;/P&gt;&lt;P&gt;replicate=&amp;amp;j;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc datasets library=work;&lt;/P&gt;&lt;P&gt;append base=work.x1 data=work.x force;&lt;/P&gt;&lt;P&gt;proc datasets library=work;&lt;/P&gt;&lt;P&gt;append base=work.y1 data=work.y force;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend reg_loop;&lt;/P&gt;&lt;P&gt;%reg_loop;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you have any suggestions? Any idea will be much appreciated! &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for you time and help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dimos&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2014 12:59:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Restrict-a-coefficient-in-regression-analysis-with-SAS-IML/m-p/181730#M1811</guid>
      <dc:creator>Dimos</dc:creator>
      <dc:date>2014-04-16T12:59:59Z</dc:date>
    </item>
    <item>
      <title>Re: Restrict a coefficient in regression analysis with SAS/IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Restrict-a-coefficient-in-regression-analysis-with-SAS-IML/m-p/181731#M1812</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have many suggestions:&lt;/P&gt;&lt;P&gt;1) Get rid of the macro loop. See the article &lt;A href="http://blogs.sas.com/content/iml/2012/07/18/simulation-in-sas-the-slow-way-or-the-by-way/" title="http://blogs.sas.com/content/iml/2012/07/18/simulation-in-sas-the-slow-way-or-the-by-way/"&gt;Simulation in SAS&lt;/A&gt; for a quick overview.&amp;nbsp; The IML language has a DO loop, so you can perform all of the looping inside SAS/IML.&lt;/P&gt;&lt;P&gt;2) Bootstrapping in SAS/IML is covered in Chapter the book &lt;EM&gt;&lt;A href="http://support.sas.com/publishing/authors/wicklin.html"&gt;Simulating Data with SAS&lt;/A&gt;. &lt;/EM&gt;The book describes dozens of ways to make your program run faster.&amp;nbsp; If you are planning to run other simulations, this book will save you time. &lt;/P&gt;&lt;P&gt;3) You don't specify your version of SAS/IML, but the primary trick to bootstrapping is sampling with replacement from the data. Therefore, see how to use the SAMPLE function in SAS/IML by reading the article &lt;A href="http://blogs.sas.com/content/iml/2014/01/23/sampling-with-replacement-easier/" title="http://blogs.sas.com/content/iml/2014/01/23/sampling-with-replacement-easier/"&gt; Sampling with replacement: Now easier than ever in the SAS/IML language - The DO Loop&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;All those tips will make your program more efficient.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With regard to your question of running a linear regression with a restricted parameter, I am not convinced that you can't use PROC REG and the RESTRICT statement.&amp;nbsp; Isn't the parameter value the same for all of the simulated sample?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At any rate, if you decide to solve the regression problem in SAS/IML, here's what I'd try.&lt;/P&gt;&lt;P&gt;The model is Y = X*beta + eps&lt;/P&gt;&lt;P&gt;If you want to restrict beta&lt;J&gt; to some known value c, then define U to be the X matrix without the j_th column and let gamma be beta without the j_th row.&amp;nbsp; Rewrite the model as &lt;/J&gt;&lt;/P&gt;&lt;P&gt;Y = U*gamma + X[,j]*c + eps&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;Y - X[,j]*c = U*gamma + eps.&lt;/P&gt;&lt;P&gt;In other words, define Z = Y - X[,j]*c&amp;nbsp; and then solve the OLS model Z = U*gamma + eps to estimate the p-1 unrestricted parameters.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2014 13:56:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Restrict-a-coefficient-in-regression-analysis-with-SAS-IML/m-p/181731#M1812</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2014-04-16T13:56:45Z</dc:date>
    </item>
    <item>
      <title>Re: Restrict a coefficient in regression analysis with SAS/IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Restrict-a-coefficient-in-regression-analysis-with-SAS-IML/m-p/181732#M1813</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Rick,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have done the loop you proposed in another step. I just included to get a more general idea. I am bootstrapping the residuals of a VAR model and then re-generate the state variables for each replication like this Y&lt;T&gt; = a*Y[t-1] + simulated_errors&lt;T&gt;. Anyway, I had no problem in the simulation itself.&amp;nbsp; I have the book you propose as well as the Statistical Programming with SA/IML software and they helped me in this respect.&lt;/T&gt;&lt;/T&gt;&lt;/P&gt;&lt;P&gt;I am using the 9.22 version of sas. The restriction changes in each simulation, that's the problem with the restrict statement. The restrict statement accepts a variable that it is in the model statement. I haven't found a way to make it take just the value of this variable in each replication, that's why I am trying with IML. I think I got what you proposed above. I will try it and review the post accordingly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dimos&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2014 15:14:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Restrict-a-coefficient-in-regression-analysis-with-SAS-IML/m-p/181732#M1813</guid>
      <dc:creator>Dimos</dc:creator>
      <dc:date>2014-04-16T15:14:50Z</dc:date>
    </item>
    <item>
      <title>Re: Restrict a coefficient in regression analysis with SAS/IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Restrict-a-coefficient-in-regression-analysis-with-SAS-IML/m-p/181733#M1814</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sounds good.&amp;nbsp; Try my formula on a simple example and compare it with the PROC REG results to see if it work. Best wishes.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2014 15:17:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Restrict-a-coefficient-in-regression-analysis-with-SAS-IML/m-p/181733#M1814</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2014-04-16T15:17:23Z</dc:date>
    </item>
  </channel>
</rss>

