Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Simulating the Central Limit Thereom

    I am attempting to write a program,wherein I wish to simulate the Central Limit Theorem (the result that the distribution of sample averages less the true mean and scaled by the standard deviation has a standard normal limiting distribution). As a result, I wrote the following code:

    Code:
    program normal10, rclass
    drop _all
    quietly set obs 10
    generate x= rnormal(0,1)
    sum x
    return scalar meanforonedraw=r(mean)
    return scalar stdevforonedraw=r(sd)
    end
    simulate Zn=(10^0.5)*(r(meanforonedraw)/r(stdevforonedraw)), reps(1000): normal10
    I obtain the error message: "Expression must be bound in parantheses". I fail to see how I have not done that. Any help is much appreciated.

  • #2
    The error message means exactly what it says, and the syntax shown at -help simulate- is quite clear: the expression after the equals sign has to be bound in parentheses. Your expression has various parentheses contained in it, but you have to wrap the whole thing in partentheses:
    Code:
    simulate Zn= ((10^0.5)*(r(meanforonedraw)/r(stdevforonedraw))), reps(1000): normal10
    That said, this is a pretty minimalist demonstration of the central limit theorem, as your underlying distribution is itself already normal. In fact, this result doesn't even require the central limit theorem: you can get it from the fact that the normal distribution family is stable. It's a lot more eye-opening if you do this with a distribution that is very different from normal, for example using an exponential distribution.

    Comment


    • #3
      Thanks a lot Clyde. I plan to compare this to when the parent distributions are not normal. This is just the first part of the simulation. The second simulation is going to make use of a Bernoulli RV. Really appreciate it.

      Comment


      • #4
        Very usefull

        Comment

        Working...
        X