Announcement

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

  • Generate fake data

    Hi all, I am trying to write some exam questions and would like to generate some histograms using fake data. I would like to be able to set the mean and SD for these variables. Does anyone know how to do that? I have tried
    Code:
    gen y = rnormal()
    but that will not allow me to set the mean and SD to 100 +- 20, for example.

  • #2
    From help rnormal
    Code:
    rnormal(m, s)
           Description:  normal(m,s) (Gaussian) random variates, where m is the mean and s is the standard deviation
    
                         The methods for generating normal (Gaussian) random variates are taken from Knuth (1998, 122-128); Marsaglia, MacLaren, and Bray (1964); and Walker (1977).
           Domain m:     c(mindouble) to c(maxdouble)
           Domain s:     0 to c(maxdouble)
           Range:        c(mindouble) to c(maxdouble)
    Code:
    . set obs 100
    number of observations (_N) was 0, now 100
    
    . gen double x = rnormal(100,20)
    
    . su x
    
        Variable |        Obs        Mean    Std. Dev.       Min        Max
    -------------+---------------------------------------------------------
               x |        100    100.3557     19.5449   46.28238   155.8972
    I hope that this helps.

    Comment


    • #3
      Oops. Not sure how I missed that! I think I must have been looking at help normal(). Thank you so much!

      Comment

      Working...
      X