How to run Julia script and function from terminal?
<p>I'm learning the Julia language and followed some tutorials to test OLS (ordinary least squares) estimation in Julia. First, I need to simulate a dataset of dependent variable ("Y"), independent variables ("X") ,error terms (epsilon) and parameters. The script is like:</p>

<pre><code># ols_simulate ：generate necessary data
using Distributions
N=100000
K=3
genX = MvNormal(eye(K))
X = rand(genX,N)
X = X'
X_noconstant = X
constant = ones(N)
X = [constant X]

genEpsilon = Normal(0, 1)
epsilon    = rand(genEpsilon,N)
trueParams = [0.1,0.5,-0.3,0.]
Y = X*trueParams + epsilon 
</code></pre>

<p>and then I defined an OLS function</p>

<pre><code>function OLSestimator(y,x)
    estimate = inv(x'*x)*(x'*y)
    return estimate
end
</code></pre>

<p>What I planed to do is first to simulate data from terminal with command:</p>

<pre><code>ols_simulate
</code></pre>

<p>and hope this step generates and stores data properly, and then I could call <code>olsestimator</code> . But after trying this, when I typed <code>mean(Y)</code> in Julia REPL, it gives me an error message like</p>

<pre><code>Error: UnderdefvarError: Y not defined
</code></pre>

<p>it seems the data are not stored properly. More generally, if I have multiple scripts (scripts and function), how can I use the data generated by one from others in the terminal? </p>

<p>Thank you.</p>