1
$\begingroup$

Let say I have below model

$y_{i,t} = 1 + X_1 + X_2 + {\gamma}_i + \epsilon_{i,t}, \epsilon_{i,t} \sim N \left(0, 1 \right), {\gamma}_i \sim N \left(0, \gamma \right)$

Here, the panel it is represented by suffix $i$ and there is time dependent measures for each $i$ which is represented by $t$

Another constraint is that, within each panel all observations have correlation coefficient as 0.65.

Based on this model, I need to generate 100 datapoints for further analysis.

Can you please help on pointer how I can I generate data based on above data generation process using R?

$\endgroup$
7
  • $\begingroup$ $\gamma_i$ is generated from a normal distribution with variance $\gamma$? $\endgroup$
    – jros
    Jun 29, 2022 at 17:15
  • $\begingroup$ What are $X_1$ and $X_2$? Would the correlation coefficient refer to the correlation between $y_{i,t}$ and $y_{i,s}$ for all $i$ and all $t\ne s$? Shall we presume (as is strongly implied) that all explicitly named random variables are independent? $\endgroup$
    – whuber
    Jun 29, 2022 at 19:22
  • $\begingroup$ @whuber I only know that $X_1$ and $X_2$ are 2 exogenous variables (fixed effect). For your remanning questions, yes all are correct $\endgroup$ Jun 29, 2022 at 21:53
  • $\begingroup$ This looks like some admixture of mathematical and programming notation, making it difficult to understand. Perhaps you mean to write $$y_{i,t}=\beta_0 + \beta_1 X_{i,1} + \beta_2 X_{i,2} + \gamma_i + \epsilon_{i,t}.$$ If not, please clarify what you mean. $\endgroup$
    – whuber
    Jun 29, 2022 at 22:34
  • 1
    $\begingroup$ @whuber Your notation is perfect. The main issue I am finding in generating realisations is how to accommodate the correlation of 0.65 $\endgroup$ Jun 30, 2022 at 6:52

1 Answer 1

0
$\begingroup$

This answer assumes the standard deviation of the Normal distribution you're generating $\gamma_i$ from is NOT $\gamma$.

You could generate data by defining a few function in R similar to this:

epsilonGenerator <- function() {
    eps_i = rnorm(1, mean=0, sd=1) 
    return eps_i
}

gammaGenerator <- function(stdev) {
    gamma_i = rnorm(1, mean=0, sd=stdev)
    return gamma_i
}

dataGenerator <- function(X1,X2) {
    y_i = 1 + X1 + X2 + gammaGenerator(stdev) + epsilonGenerator()
    return y_i
}

Then simply call dataGenerator for each each pair of X1 and X2

$\endgroup$
4
  • 1
    $\begingroup$ Many thanks. How are we ensuring the constraint that states Another constraint is that, within each panel all observations have correlation coefficient as 0.65.? $\endgroup$ Jun 29, 2022 at 18:53
  • $\begingroup$ Are X1 and X2 supposed to have correlation = 0.65? Because then we would need to look at how X1 and X2 are generated. $\endgroup$
    – jros
    Jun 29, 2022 at 19:00
  • $\begingroup$ Actually I am not sure. It is not clear from the model documentation. However, being exogenous variables should not they be uncorrelated to avoid multicolinearity? $\endgroup$ Jun 29, 2022 at 19:08
  • $\begingroup$ exogenous variables are independent, but they could still be correlated and cause multicollinearity $\endgroup$
    – jros
    Jun 29, 2022 at 19:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.