<?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: Simulating nested data in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/543781#M7763</link>
    <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;But the program won't run... Why is that?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If a program does not run, please show the error that you get in the log.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This kind of simulation is discussed on p. 203 of &lt;EM&gt;Simulating Data with SAS &lt;/EM&gt;(Wicklin, 2013). I think you might have too many looks. Remember that the SET statement implicitly loops over the data.&lt;/P&gt;</description>
    <pubDate>Sun, 17 Mar 2019 10:41:32 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2019-03-17T10:41:32Z</dc:date>
    <item>
      <title>Simulating nested data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/540627#M7239</link>
      <description>&lt;P&gt;I am trying to simulate nested data but so far I couldn't figure out how to do that... So, I want to simulate 2-level data, e.g., students (level 1) clustered within schools (level 2). The model to be simulated is a random intercept model where level-2 variable (W) predicts level-1 outcome (Y).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Untitled.jpg" style="width: 200px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/27685i819E44033D5A2B8D/image-size/small?v=v2&amp;amp;px=200" role="button" title="Untitled.jpg" alt="Untitled.jpg" /&gt;&lt;/span&gt;&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to specify intercept variance, residual variance, number of level 2 units (schools), and number of level-1 units per level-2 unit (number of students per school).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be highly appreciated! Thank you in advance.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2019 01:25:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/540627#M7239</guid>
      <dc:creator>Amanda_Lemon</dc:creator>
      <dc:date>2019-03-06T01:25:06Z</dc:date>
    </item>
    <item>
      <title>Re: Simulating nested data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/540647#M7243</link>
      <description>&lt;P&gt;What have you tried so far?&amp;nbsp; What would the set of Wj values be in this simulation?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2019 04:55:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/540647#M7243</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-03-06T04:55:10Z</dc:date>
    </item>
    <item>
      <title>Re: Simulating nested data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/540652#M7244</link>
      <description>&lt;P&gt;I found a code in the "SAS for mixed models" book by Littell, 2006 (Section 12.5) -- is it allowed to copy-paste code from a book? Anyway, it has more variance parameters than I need and does not have numbers of units. So I wasn't sure how to modify that code for my purpose.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;W&amp;nbsp;would be just a normally distributed variable (so, a normal distribution of j cases).&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2019 05:44:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/540652#M7244</guid>
      <dc:creator>Amanda_Lemon</dc:creator>
      <dc:date>2019-03-06T05:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: Simulating nested data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/540974#M7271</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;, maybe you have some hints for me about how to simulate this model? Thank you in advance!</description>
      <pubDate>Wed, 06 Mar 2019 23:45:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/540974#M7271</guid>
      <dc:creator>Amanda_Lemon</dc:creator>
      <dc:date>2019-03-06T23:45:10Z</dc:date>
    </item>
    <item>
      <title>Re: Simulating nested data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/540978#M7273</link>
      <description>&lt;P&gt;SAS Press books provide the code for free, so you ought to be able to go to the web site for Littel et al or Wicklin (2013) and use the code, if you can understand it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My hint is to simulate the beta0[j] first, then simulate the Y[i,j] for each cluster.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are using the DATA step, put the beta0[j] in an array and simulate them first. Then for each cluster and subject in the cluster, simulate Y[i,j] and OUTPUT the result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are using IML, then you can vectorize the process. You can generate the beta0 vector in one statement and then loop over the clusters and generate all subjects in a vector way.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Mar 2019 00:57:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/540978#M7273</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-03-07T00:57:17Z</dc:date>
    </item>
    <item>
      <title>Re: Simulating nested data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/541638#M7395</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;, thank you! I tried to adapt the code from your book. Did I do it right? Does this code simulate the model I described in the first post? U think it does but just want to double check... The end goal is to run a power analysis. Thanks again!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mu = 0; /* intercept, or overall mean */ 
%let tau = 15; /* random intercept variance */
%let sigma = 45; /* error variance */ 
%let N2 = 200; /* number of level 2 units */ 
%let N1 = 30; /* number of level 1 units per level 2 unit */ 
%let b = 0.2; /* effect of W */ 
%let nsamples = 1000; /* number of simulated samples */ 

data power;
call streaminit(123456);
do sampleID = 1 to &amp;amp;nsamples; 
 do j = 1 to &amp;amp;N2;
   rand_int = rand('Normal', 0, sqrt(&amp;amp;tau)); 
   W = rand('Normal', 0, 1);
   do i = 1 to &amp;amp;N1;
      rand_e = rand('Normal', 0, sqrt(&amp;amp;sigma));
      Y = &amp;amp;mu + &amp;amp;b * W + rand_int + rand_e;
      output;
   end; 
 end; 
end; 
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Mar 2019 22:36:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/541638#M7395</guid>
      <dc:creator>Amanda_Lemon</dc:creator>
      <dc:date>2019-03-08T22:36:28Z</dc:date>
    </item>
    <item>
      <title>Re: Simulating nested data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/541660#M7399</link>
      <description>&lt;P&gt;I'm sure you understand that I cannot double check the programs for everyone who reads my books or blogs.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your simulation, you need to make sure to specify the meaning of the W variable. In your simulation, it looks like W is a random effect because it assumes different values for each&amp;nbsp;subject&amp;nbsp;in each sample. This is one (valid) model. Another valid model is to assume that W is a fixed effect. In a fixed effect, the W[j] would be the same for each sample. You would have to move the SAMPLE loop to just outside the loop over i (individual units). If you do that, you probably want to sort by SAMPLE before you perform the BY-group analysis of the simulated data. These issues are discussed on p. 199-200 and p. 230-231.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect you intend W to be a fixed effect because you use b as the size of the effect as opposed to assuming W ~ N(0, s) for some variance component.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Mar 2019 00:23:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/541660#M7399</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-03-09T00:23:57Z</dc:date>
    </item>
    <item>
      <title>Re: Simulating nested data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/543759#M7761</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;, thank you so much! Understood. Yes, W should be a fixed effect.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ran into a different problem now... Instead of simulating the level-2 variable W, I wanted to import values of this variable from an existing data set. But the program won't run... Why is that? I also tried to put W values into an array first but that didn't work either...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mu = 0; /* intercept, or overall mean */ 
%let tau = 15; /* variance of random intercept */
%let sigma = 45; /* error variance */ 
%let N1 = 300; /* number of level 1 units per level 2 unit */ 
%let b = 0.3; /* effect of W */ 
%let nsamples = 2; /* number of simulated samples */ 

data power;
call streaminit(123456); 
set my_set; /* this set has W (200 values) */ 
do j = 1 to 200;
   rand_int = rand('Normal', 0, sqrt(&amp;amp;tau)); 
   do sampleID = 1 to &amp;amp;nsamples; 
     do i = 1 to &amp;amp;N1;
       rand_e = rand('Normal', 0, sqrt(&amp;amp;sigma));
       Y = &amp;amp;mu + &amp;amp;b * W + rand_int + rand_e;
       output;
     end; 
   end; 
end; 
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Mar 2019 02:44:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/543759#M7761</guid>
      <dc:creator>Amanda_Lemon</dc:creator>
      <dc:date>2019-03-17T02:44:42Z</dc:date>
    </item>
    <item>
      <title>Re: Simulating nested data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/543781#M7763</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;But the program won't run... Why is that?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If a program does not run, please show the error that you get in the log.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This kind of simulation is discussed on p. 203 of &lt;EM&gt;Simulating Data with SAS &lt;/EM&gt;(Wicklin, 2013). I think you might have too many looks. Remember that the SET statement implicitly loops over the data.&lt;/P&gt;</description>
      <pubDate>Sun, 17 Mar 2019 10:41:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/543781#M7763</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-03-17T10:41:32Z</dc:date>
    </item>
    <item>
      <title>Re: Simulating nested data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/543839#M7765</link>
      <description>&lt;P&gt;Well, that's the thing -- there is no error, there is quite literally nothing... Seems that it's just running without any result. So I need to force SAS to close and then open it again.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The online version of the book, provided by my university's library, doesn't have page numbers... Do you mind noting the section/subsection number that you were referring to?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you again for your help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Mar 2019 21:59:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/543839#M7765</guid>
      <dc:creator>Amanda_Lemon</dc:creator>
      <dc:date>2019-03-17T21:59:51Z</dc:date>
    </item>
    <item>
      <title>Re: Simulating nested data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/543841#M7766</link>
      <description>&lt;P&gt;Section 11.3.2 "A Linear Model Based on Real Data" starts on&amp;nbsp;p. 202&lt;/P&gt;</description>
      <pubDate>Sun, 17 Mar 2019 22:03:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/543841#M7766</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-03-17T22:03:43Z</dc:date>
    </item>
    <item>
      <title>Re: Simulating nested data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/543846#M7767</link>
      <description>&lt;P&gt;Thank you! So, as far as I understood, examples in this section use parameters obtained from the analysis&amp;nbsp;of real data. But I have actual&amp;nbsp;data that I want to use in the simulation rather than parameters. So, in other words, I want to import Level-2 variable values and simulate Level-1 variable values. You mentioned that the problem might be in the SET statement -- is there another way to import values (especially if there are many observations, like 2000)?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Mar 2019 22:41:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/543846#M7767</guid>
      <dc:creator>Amanda_Lemon</dc:creator>
      <dc:date>2019-03-17T22:41:54Z</dc:date>
    </item>
    <item>
      <title>Re: Simulating nested data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/543851#M7768</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;So, as far as I understood, examples in this section use parameters obtained from the analysis&amp;nbsp;of real data. But I have actual&amp;nbsp;data that I want to use in the simulation rather than parameters&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See the examples in section 11.3.2.2 "Simulations That Use the Sample Data," which use the SET statement and read in actual data.&lt;/P&gt;</description>
      <pubDate>Sun, 17 Mar 2019 23:17:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/543851#M7768</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-03-17T23:17:07Z</dc:date>
    </item>
    <item>
      <title>Re: Simulating nested data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/543853#M7769</link>
      <description>&lt;P&gt;Got it! Thank you. The problem is solved -- I just needed to move the SET statement inside the first loop.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Mar 2019 23:34:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Simulating-nested-data/m-p/543853#M7769</guid>
      <dc:creator>Amanda_Lemon</dc:creator>
      <dc:date>2019-03-17T23:34:47Z</dc:date>
    </item>
  </channel>
</rss>

