Announcement

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

  • generate a random integer between a and b within the dofile and use it in the next moves

    I was trying to generate one positive random integer between, say, 0 and 10, in my dofile. In doing so, I have to set obs 1 to indicate that I want only one random integer. But the problem is I already read one dataset into stata which has certain observations. Obviously, stata gives the error: observation number out of range
    I tried to use tempvar, it also requires to state your observations, which is only 1 in this case, and stata gives the same error: observation number out of range
    Code:
    clear all
    sysuse auto
    set seed 123
    set obs 1
    gen random=floor((10-0+1)*runiform()+0)
    So, my question is, how can I generate one positive random integer and use this random integer in the next moves within my dofile where I already loaded some observations.
    Thanks!

  • #2
    Code:
    help scalar
    also
    Code:
    help runiformint()

    Comment


    • #3
      Originally posted by Joseph Coveney View Post
      Code:
      help scalar
      also
      Code:
      help runiformint()
      Perfect!

      Comment

      Working...
      X