Announcement

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

  • How to create a variable that has a distribution that is conditional on another variable?

    Hi all,

    Sorry if this has been asked before or is straightforward, but I can't seem to find anything on this.

    I'm trying to run a simulation and I need to create two variables.
    1. The first variable (X) is normally distributed with mean 0 and variance 4.
    2. The second variable (U), conditional on X, has a standard normal distribution. That is, U|X ∼ N (0, 1).
    I can do 1 [g x = rnormal(0,2)], but I can't figure out how to do 2? Any insight would be greatly appreciated!

    Thanks
    Jerome

  • #2
    The second variable (U), conditional on X, has a standard normal distribution. That is, U|X ∼ N (0, 1).
    This makes no sense. N(0, 1) is an unconditional distribution--it does not depend in any way on X.

    Going far out on a speculative limb, I think what you meant to say is that U|X ~ N(X, 1). That is U is normally distributed with mean = X and variance 1. The code for that would be -gen u = rnormal(x, 1)-. By the way, don't forget to set the random number seed before you do any of this.

    Comment


    • #3
      Hi Clyde,

      First of all, thank you for the quick response!!

      I agree it's somewhat nonsensical. For context, this is for a PhD econometrics course. The directions that were given to me are:

      Consider the following model:

      Yi = 1{a + bXi − Ui ≥ 0}.

      Let Xi ∼ N (0, 4) and Ui|Xi ∼ N (0, 1). set a=1, b=1. Generate 2000 random samples of size 1000,



      Based on your comments, perhaps my professor meant something like:

      Code:
      g X = rnormal(0,2)
      g Y = (1 + X - rnormal(0,1))
      Does that seem reasonable to you?

      Also, why should I set the random number seed? Is that for reproducibility reasons?

      Thanks again!
      Jerome

      Comment


      • #4
        Well, it still seems peculiar that he rights Ui | Xi ~ N(0,1) since N(0,1) is independent of Xi. BUT, seeing the full context, Yi = 1{a + bXi − Ui ≥ 0}, this is immediately recognizable as a probit model.

        So I would code this as:
        Code:
        gen X = rnormal(0, 2)
        gen U = rnormal(0, 1)
        gen Y = (a + b* X - U >= 0)
        By the way, I'm assuming here, as you apparently are, that when your teacher uses the notation N(p1, p2) he or she means p2 to be the variance. Not everybody follows that convention: some would mean p2 to be the standard deviation.

        Also, why should I set the random number seed? Is that for reproducibility reasons?
        Yes, exactly so.

        Comment

        Working...
        X