Announcement

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

  • Using a probability variable to generate random dummy´s

    I have a probability (prob) variable, created by myself for each observation. I want to generate a dummy wich takes values 1 o 0 (for each obs) with the probability that indicates the prob variable.

  • #2
    Consider a variable prob with values like 0.2, 0.5, 0.9. Then

    Code:
    gen wanted = runiform() < prob
    will be 1 with probability prob and 0 otherwise.

    Comment


    • #3
      Nicks answer is also discussed in this Stata tip: https://doi.org/10.1177%2F1536867X0700700309 except that at the time the function runiform() was called uniform()
      Last edited by Maarten Buis; 08 Feb 2019, 08:45.
      ---------------------------------
      Maarten L. Buis
      University of Konstanz
      Department of history and sociology
      box 40
      78457 Konstanz
      Germany
      http://www.maartenbuis.nl
      ---------------------------------

      Comment


      • #4
        thanks!

        Comment

        Working...
        X