title: Simulation to generate balanced longitudinal data
body: <p>I want to do some simulation in R, I have written a code but I am not getting any headway. I will be grateful if anyone could help. I want to generate longitudinal data for three time points with different observations such that for any 1000 simulations it generates different observations. Note that the data should be balanced. equal number of TRT and Placebo at each time point. I am really struggling with it. Any help will be well appreciated. Below is the code;</p>
  
  <pre><code>ns=20
  x1=rnorm(ns,0,1)
  x2=rnorm(ns,5,5)
  x3=rnorm(ns,10,5)
  U=c(x1,x2,x3)
  ans=matrix(rep(0,200),nrow=100)
  for(k in 1:100)
  {   simdata=data.frame(CD=U,
                         Time=factor(rep(c(1,2,3),each=ns)),
                         treatment=sample(rep(c('Trt','placebo'),ns/2)))
  ans[k,]=table(simdata$treatment)
  }
  </code></pre>