Announcement

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

  • Achieving different results when trying to recreate stata lesson

    Hello, I am just starting to learn the stata software and I am trying to work through the stata lessons.
    I am typing exactly what is written in the lesson - but I receive totally different results.

    I type:

    clear
    set seed 100
    set obs 10
    generate famid = int(runiform()*4)
    generate age = int(runiform()*10)
    list

    and I receive this:

    +-------------+
    | famid age |
    |-------------|
    1. | 3 9 |
    2. | 1 1 |
    3. | 3 5 |
    4. | 0 4 |
    5. | 3 5 |
    6. | 1 6 |
    7. | 3 1 |
    8. | 2 2 |
    9. | 3 8 |
    10. | 3 0 |
    +-------------+

    instead I should receive this:

    +-------------+
    | famid age |
    |-------------|
    1. | 2 3 |
    2. | 0 5 |
    3. | 3 0 |
    4. | 0 2 |
    5. | 0 6 |
    6. | 2 1 |
    7. | 1 6 |
    8. | 0 1 |
    9. | 1 4 |
    10. | 2 0 |
    +-------------+

    What am I doing wrong? I can not continue with the example if I generate these different results.

    Thanks for you help - I really appreciate it!

  • #2
    My guess is that you are using a different random number generator from that used to create the results.

    See e.g.

    Code:
    help set rng
    for much more.

    The example is out-of-date for other reasons. In any recent Stata it would be better to use runiformint().

    Comment


    • #3
      To rephrase Nick's answer: the "lesson", i.e., the example code was probably created in an earlier version of Stata. Back then, Stata produced different random numbers.

      My advice for a beginner is this: do not bother understanding issues related to random number generators quite yet. Simply type:

      Code:
      version 13 , user
      at the top of your do-file. That is, run the code:

      Code:
      version 13 , user // <- new line
      clear
      set seed 100
      set obs 10
      generate famid = int(runiform()*4)
      generate age = int(runiform()*10)
      list
      to reproduce the results of this example.

      Once you get some basic examples running, you can come back and read more about

      Code:
      help version
      and, as Nick has suggested

      Code:
      help set rng

      Comment

      Working...
      X