Announcement

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

  • Generate Dummy Variables from Multinomial Distribution

    I am currently stuck on how to program a data generation process, I am using stata 15.1:

    I have a probabilistic defined dummy variable, which could be defined as 6 different states.

    For example - in the first observation I have the following:

    [p1 p2 p3 p4 p5 p6]

    with each probability as its own defined variable and all six probabilities sum to 1.

    I would like to generate 6 dummy variables from these probabilities:

    [d1 d2 d3 d4 d5 d6]

    where the probability of the dummy variable equaling 1 is equal to the probabilities defined above. I've tried a binomial distribution, but because these are dependent (all the other dummies must equal 0 if one takes the value of 1) I am having trouble. A multinomial distribution seems likes the best choice, but I am unsure on how to program the generation of such variables without turning to matlab or R.

    Thank you for the guidance,

    Eric Wilbrandt


  • #2
    Mike Lacy gets a tip of the hat for this advice using the -irecode- function, and I think you would type:

    Code:
    gen dummy =  irecode(runiform(),p1,p1+p2,p1+p2+p3,...)
    tabulate dummy, gen(d)
    Does that work? If that's not quite what you had in mind, can you show a data example?
    Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

    When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

    Comment


    • #3
      Weiwen Ng , this is exactly what I was looking for. Thank you very much for pointing me in the right direction. Mike Lacy thanks for pointing this out in another post.

      Comment

      Working...
      X