Announcement

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

  • Generate a distribution from parameters.

    Hi, how can i create a distribution knowing only parameters? I have to estimate a distribution of income for several countries. I think lognormal or Weibull are the best solution to produce preliminary results. For the lognormal case i have only mu and sigma. How can i generate a distribution such that on the y i have people in thousands and on the x income levels? At the end i need to get something like this
    Click image for larger version

Name:	Schermata 2017-06-24 alle 16.12.34.png
Views:	1
Size:	109.6 KB
ID:	1399242

  • #2
    Run -help random number- to see the broad array of distributions that can be directly generated in Stata. For lognormal, there is no specific function, but you generate instead a normal distribution with appropriate mean and standard deviation and then exponentiate those results. (The appropriate mean and standard deviation are simple functions of the mean and standard deviation of the log normal distribution itself--see any standard mathematical statistics reference, or, for that matter, Wikipedia, for the formulas.) For Weibull, you have to specify shape,and scale parameters. Those, too, are related to the mean and standard deviation, although it is not so simple to get shape and scale from mean and standard deviation.

    As a matter of good programming practice, remember to set a seed for the random number generator before you start generating variables so that your results will be reproducible.

    Comment


    • #3
      These are my codes.

      global obs = 310.000.000
      set obs $obs - i get an error message here
      gen id = _n
      gen n = rnormal(m,s) where m and s are mean and variance

      But when i type gen r = exp(n) i get missing values.
      Last edited by Dora Macolino; 24 Jun 2017, 11:34.

      Comment


      • #4
        Dora:
        Stata is queasy about thousands separators.

        Try instead:
        Code:
        . global obs = 310000000
        
        .  set obs $obs
        number of observations (_N) was 0, now 310,000,000
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          Same result. I get values for n. The problem is with exp(n).
          Moreover, since i should produce an income distribution, my random numbers should be generated in the interval 0 to 210000.
          Last edited by Dora Macolino; 24 Jun 2017, 11:59.

          Comment


          • #6
            Up

            Comment


            • #7
              Re #5. You are trying to create numbers that are too large to represent in Stata's floating-point. The largest value of n that -exp()- can work with is 709. (If you run -help exp()- you will see this there.) The reason is that anything bigger than exp(709) is just too large to fit into the floating point representation that Stata uses.

              I guess my question is why you are trying to work with numbers that are that astronomically large. Why not scale them all down by some large factor?

              Comment

              Working...
              X