Announcement

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

  • Random sample

    Hello to all, I try to learn stata by myself as a economist,

    So I want to make a boucle to make a random sample

    I want to draw 500 samples of 1000 obs, from 10000 obs

    Also in this boucle, if possible, i want to create variable like
    x1 -> x1_mean , x2-> x2_mean etc...

    Thank to help me, I did'nt put the code because is not working

  • #2
    I try that
    Code:
    forvalue j = 1/5{
    generate x`j'_mean = .
    }
    //
    
    forvalue i = 1/500{
    sum x1 if runiform()<(0.1)
    replace x1_mean = r(mean) in `i'
    sum x2 if runiform()<(0.1)
    replace x2_mean = r(mean) in `i'
    sum x3 if runiform()<(0.1)
    replace x3_mean = r(mean) in `i'
    sum x4 if runiform()<(0.1)
    replace x4_mean = r(mean) in `i'
    sum x5 if runiform()<(0.1)
    replace x5_mean = r(mean) in `i'
    }
    It's working, but do you thing I can reduce or simplified my loops?

    Thank
    Last edited by Patrick Turcotte; 07 Mar 2019, 22:01.

    Comment


    • #3
      Originally posted by Patrick Turcotte View Post
      Hello to all, I try to learn stata by myself as a economist,

      So I want to make a boucle to make a random sample

      I want to draw 500 samples of 1000 obs, from 10000 obs

      Also in this boucle, if possible, i want to create variable like
      x1 -> x1_mean , x2-> x2_mean etc...

      Thank to help me, I did'nt put the code because is not working
      Please read loops and not boucle...

      French word for loops ;-)

      Comment


      • #4
        Looks like variation on the bootstrap to me. Maybe the bootstrap prefix, the bsample command, or the vce(bootstrap) option helps.
        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment


        • #5
          Thanks , I will try that

          Comment

          Working...
          X