Hello Julia users!
I am trying to make a hypothetical dataset of variables X2, Z1, Z2, and ε with some mean and covariance. Using
Random packages works just fine, but I was wondering if I can assign the variable names and generating an array at the same time.
using LinearAlgebra using Statistics, Distributions, Random Random.seed!(123) μ = [0.0; 0.0; 0.0; 0.0]; # order: X2, Z1, Z2, ε Σ = [1.0 0.3 -.4 0.5; 0.3 1.0 0.4 0.0; -.4 0.4 1.0 0.0; 0.5 0.0 0.0 3.0]; N = 2000; XZε = rand(MvNormal(μ,Σ),N) X2 = XZε[1,:] Z1 = XZε[2,:] Z2 = XZε[3,:] ε = XZε[4,:]
As you can see, variable names X2, Z1, Z2, and ε are assigned after XZε is created. Is there any way I can do that in fewer codes?
Thank you for your input!