Announcement

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

  • Simulation & Random variable generation

    Hello dears

    I have two questions concerning the simulation and random variable generation

    Q1: How can I generate a normlay distributed random variable that have specific mean, sd ,skewness and kurtosis?

    Q2: when I running me-written programs, I encountered some problems. The situation is like this. I made two rclass programs, one is nested and the other is nesting. which means nesting rclass written program is calling the nested program. After completing debugging and finding there was no error, I was running the simulation. Then I discovered that the nesting program properly returned values but the nested program didn't change them. is there anybody knowing the reason why the simulation(stata cmd simulate) produced the results?

  • #2
    See -help rnormal()- for how to generate normally distributed random numbers with desired mean and standard deviation. The skewness of any normal distribution is 0, and the kurtosis of any normal distribution is 3--you cannot specify these.

    I do not understand the terminology you are using in Q2. Even if I did, you give us very little information about what went wrong. To get a helpful answer you should post the code that is not working along with how Stata responds to it, as well as some sample data.

    To post sample data, please use -dataex-. If you do not already have it, run -ssc install dataex-. The instructions for using it are in -help dataex-.

    To post code and results, copy from Stata's Results window or your log file to your computer's clipboard and then paste that into a code block here. (Instructions for setting up a code block can be found in FAQ #12, 7th paragraph.) Don't edit anything: the details are important and we need to see exactly what you did and what happened.

    Comment


    • #3
      Million thanks Clyde

      Concerning Q1, the distribution that I want to make is not normal. the things I'd like to control are actually kurtosis, mean and sd ( especially kurtosis, stata can generate normally distributed observations with given mean and sd as you mentioned) so that i could generate a variable that contains less possibility which extream observations occur and more possibility which mean-centered observations occur at the same time than normally distributed observations.
      Last edited by Yujuana Min; 17 Mar 2016, 20:12.

      Comment


      • #4
        I see. I don't know how to generate random samples with specified kurtosis, mean, and standard deviation. In the familiar parametric distribution families there are usually relations among these that preclude independently specifying each of these. Perhaps somebody else knows how and will chime in.

        I would also call your attention to the fact that the sample kurtosis is not necessarily a faithful reflection of the kurtosis of the distribution from which the sample is drawn: sample size imposes limits on sample kurtosis. See http://www.stata-journal.com/sjpdf.h...iclenum=st0204.

        Comment


        • #5
          Regarding Q1, as Clyde Schechter pointed out, you can use rnormal(m,s) to generate normally distributed random variates with mean m and standard deviation s. You can try the user-written commands rnonnormal and rmvnonnormal that respectively simulate univariate and multivariate nonnormal distributions with specific skewness and kurtosis - the specified skewness and kurtosis control the degree to which the data depart from normality. These commands are based on a method proposed by Fleishman (1978). findit rnonnormal will tell you more.

          I hope this helps.

          -- Kreshna

          Comment


          • #6
            Mean, SD, skewness and kurtosis can't be sufficient to specify a distribution, as with nothing else said the fifth and higher moments are unspecified.

            Comment


            • #7
              I am wondering if there has been a change in Stata after the development (and publication) of the user-written command rnonnormal:
              Code:
              findit rnonnormal
              as discussed in this thread.

              In the help-file, an example is given:
              set seed 777
              rnonnormal, n(1000) skewness(1.5) kurtosis(3.75)
              return list
              And the results are:
              scalars:
              r(a) = -.2210276210126192
              r(b) = .8658862035231392
              r(c) = .2210276210126192
              r(d) = .0272206991580893
              r(kurt) = 3.612271257758691
              r(skew) = 1.452691091582093
              r(sd) = 1.027291300889708
              r(mean) = .0202128245923377

              However, in Stata 18, the exact same code (as above) produces the following results:

              scalars:
              r(a) = -.2210276210126174
              r(b) = .8658862035231379
              r(c) = .2210276210126174
              r(d) = .02722069915809
              r(kurt) = 5.90735919625895
              r(skew) = 1.812362793254485
              r(sd) = .9956891401281293
              r(mean) = -.0435136538969818

              It is quite different, and also the returned kurtosis is now 5.91. Is this as expected?

              Comment


              • #8
                Originally posted by Frode Andre View Post
                I am wondering if there has been a change in Stata after the development (and publication) of the user-written command rnonnormal:
                Code:
                findit rnonnormal
                as discussed in this thread.
                Yes.

                If you look at the ado file for that user-written command, although there is no Stata release given, the code has a last-updated date of 2013-12-27 and the date on its help file (containing those results) is 2013-03-07.

                With Release 14 in April of 2015, Stata introduced a different pseudorandom number generator.

                Comment

                Working...
                X