<?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 time-varying covariates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Simulating-time-varying-covariates/m-p/241186#M44667</link>
    <description>You may also notice the values are the same as the previous record. Because there is no data set, there is no output and reinitialization of the PDV. &lt;BR /&gt;&lt;BR /&gt;You need to set them to missing at the top of the loop. I recommend the call missing routine.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Wed, 30 Dec 2015 02:02:31 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2015-12-30T02:02:31Z</dc:date>
    <item>
      <title>Simulating time-varying covariates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simulating-time-varying-covariates/m-p/241095#M44626</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to simulate a longitidunal data with time-varying variables but I am having some trouble. The code seems to be fine but it's not yielding an ouput (i.e. it runs forever). The problem arise when I use the do while statements. Basically when&amp;nbsp;Yt&amp;nbsp;= 1, no records are included for that individual&amp;nbsp;from time t + 1 onwards. For instance, if for individuals with Y1 =1, there should be no record available (L2, A2 and Y2 will be missing).&lt;/P&gt;&lt;P&gt;Can someone help me fix the code. Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data test;&lt;BR /&gt;Call streaminit(234);&lt;BR /&gt;&lt;BR /&gt;do id = 1 to 1000;&lt;BR /&gt;U = rand("normal",0, 0.25);&lt;BR /&gt;L0 = rand("normal", 5.5 + U, 0.04);&lt;BR /&gt;A0 = rand("Bernoulli", expit(5 - L0));&lt;BR /&gt;&lt;BR /&gt;L1 = rand("normal",0.9*L0 + A0 + 0.1*U, 0.01);&lt;BR /&gt;A1 = rand("bernoulli", expit(A0 + 4.5*L1));&lt;BR /&gt;Y1 = rand("bernoulli", expit(-8 + L0 - 0.3*(A0) - U));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;do while (Y1=0);&lt;BR /&gt;L2 = rand("normal",0.9*L1 + A1 + 0.1*U, 0.01);&lt;BR /&gt;A2 = rand("bernoulli", expit(A1 + 4.5*L2)) ;&lt;BR /&gt;Y2 = rand("bernoulli", expit(-8 + L1 - 0.3*(A0 + A1) - U));&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;do while (Y2=0);&lt;BR /&gt;Y3 = rand("bernoulli", expit(-8 + L2 - 0.3*(A0 + A1 + A2) - U));&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;output;&lt;/P&gt;&lt;P&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Dec 2015 02:09:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simulating-time-varying-covariates/m-p/241095#M44626</guid>
      <dc:creator>SimRock</dc:creator>
      <dc:date>2015-12-29T02:09:56Z</dc:date>
    </item>
    <item>
      <title>Re: Simulating time-varying covariates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simulating-time-varying-covariates/m-p/241097#M44627</link>
      <description>In your do while loops you never change the variable that causes you to enter the loop (Y1, Y2) so you'll never exit the loop if you enter it. &lt;BR /&gt;&lt;BR /&gt;If Y1=0, you enter the loop, never change Y1 and are stuck...&lt;BR /&gt;&lt;BR /&gt;do while (Y1=0);&lt;BR /&gt;L2 = rand("normal",0.9*L1 + A1 + 0.1*U, 0.01);&lt;BR /&gt;A2 = rand("bernoulli", expit(A1 + 4.5*L2)) ;&lt;BR /&gt;Y2 = rand("bernoulli", expit(-8 + L1 - 0.3*(A0 + A1) - U));&lt;BR /&gt;end;&lt;BR /&gt;</description>
      <pubDate>Tue, 29 Dec 2015 02:18:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simulating-time-varying-covariates/m-p/241097#M44627</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-29T02:18:46Z</dc:date>
    </item>
    <item>
      <title>Re: Simulating time-varying covariates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simulating-time-varying-covariates/m-p/241170#M44659</link>
      <description>&lt;P&gt;Thank you Reeza, that was really helpful&lt;/P&gt;&lt;P&gt;So do you think I could do something like this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data test;&lt;BR /&gt;Call streaminit(234);&lt;BR /&gt;&lt;BR /&gt;do id = 1 to 1000;&lt;BR /&gt;U = rand("normal",0, 0.25);&lt;BR /&gt;L0 = rand("normal", 5.5 + U, 0.04);&lt;BR /&gt;A0 = rand("Bernoulli", expit(5 - L0));&lt;BR /&gt;&lt;BR /&gt;L1 = rand("normal",0.9*L0 + A0 + 0.1*U, 0.01);&lt;BR /&gt;A1 = rand("bernoulli", expit(A0 + 4.5*L1));&lt;BR /&gt;Y1 = rand("bernoulli", expit(-8 + L0 - 0.3*(A0) - U));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if&amp;nbsp;(Y1=0) then do;&lt;BR /&gt;L2 = rand("normal",0.9*L1 + A1 + 0.1*U, 0.01);&lt;BR /&gt;A2 = rand("bernoulli", expit(A1 + 4.5*L2)) ;&lt;BR /&gt;Y2 = rand("bernoulli", expit(-8 + L1 - 0.3*(A0 + A1) - U));&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;if&amp;nbsp;(Y2=0) then do;&lt;BR /&gt;Y3 = rand("bernoulli", expit(-8 + L2 - 0.3*(A0 + A1 + A2) - U));&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;output;&lt;/P&gt;&lt;P&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, it does not seem to quite work because people with Y1=1 still have records for L2, A2, Y2, which does not makes sense.&lt;/P&gt;&lt;P&gt;Can you share your wisdom once more&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Dec 2015 22:09:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simulating-time-varying-covariates/m-p/241170#M44659</guid>
      <dc:creator>SimRock</dc:creator>
      <dc:date>2015-12-29T22:09:05Z</dc:date>
    </item>
    <item>
      <title>Re: Simulating time-varying covariates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simulating-time-varying-covariates/m-p/241186#M44667</link>
      <description>You may also notice the values are the same as the previous record. Because there is no data set, there is no output and reinitialization of the PDV. &lt;BR /&gt;&lt;BR /&gt;You need to set them to missing at the top of the loop. I recommend the call missing routine.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 30 Dec 2015 02:02:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simulating-time-varying-covariates/m-p/241186#M44667</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-30T02:02:31Z</dc:date>
    </item>
    <item>
      <title>Re: Simulating time-varying covariates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simulating-time-varying-covariates/m-p/241196#M44674</link>
      <description>&lt;P&gt;Thank you very much Reeza. It worked out well. Now I am trying to automate the process by using functions like arrays, but I am having a bit of trouble. I want it to go from t=0 to t=9 for variabes A and L. For the Y variables, I would like it to go from t=1 to t=10.Could you provide some guidance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data sim;&lt;BR /&gt;Call streaminit(234);&lt;BR /&gt;array A{0:9} A0-A9; array L{0:9} L0-L9 ; array Y{1:10} Y1-Y10;&lt;BR /&gt;do id = 1 to 100;&lt;/P&gt;&lt;P&gt;do t=0 to 1;&lt;BR /&gt;U = rand("normal",0, 0.25);&lt;BR /&gt;L{0} = rand("normal", 5.5 + U, 0.04);&lt;BR /&gt;A{0} = rand("Bernoulli", expit(5 - L{0}));&lt;BR /&gt;&lt;BR /&gt;L{1} = rand("normal",0.9*L{0} + A{0} + 0.1*U, 0.01);&lt;BR /&gt;A{1} = rand("bernoulli", expit(A{0} + 4.5*L{1}));&lt;BR /&gt;Y{1} = rand("bernoulli", expit(-8 + L{0} - 0.3*(A{0}) - U));&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;do t=2 to 8;&lt;BR /&gt;if (Y{t-1}=0) then do;&lt;BR /&gt;L{t} = rand("normal",0.9*L{t-1} + A{t-1} + 0.1*U, 0.01);&lt;BR /&gt;A{t} = rand("bernoulli", expit(A{t-1} + 4.5*L{t})) ;&lt;BR /&gt;Y{t} = rand("bernoulli", expit(-8 + L{t-1} - 0.3*sum(of A{0} to A{t-1}) - U));&lt;BR /&gt;end; else do L{t}=.; A{t}=.; Y{t}=.; end;&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;t=9;&lt;BR /&gt;if (Y{t}=0) then do;&lt;BR /&gt;Y{t+1} = rand("bernoulli", expit(-8 + L{t} - 0.3*sum(of A{0} to A{t}) - U));&lt;BR /&gt;end; else do Y{t+1}=.; end;&lt;/P&gt;&lt;P&gt;output;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2015 04:39:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simulating-time-varying-covariates/m-p/241196#M44674</guid>
      <dc:creator>SimRock</dc:creator>
      <dc:date>2015-12-30T04:39:47Z</dc:date>
    </item>
  </channel>
</rss>

