Announcement

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

  • Problem replicating a seed

    Hi all,

    I am having a problem that might be just a mistake on understading how set seet works in the new Stata 14. I needed to select randomly three evaluations and create an average score per project so in my do file I set a seed, create a random number and selected the three evaluations with the largest random numbers per project. However when I run the do file, each time I get a different result. Why does that happen if each time the do file runs the seed is set at the same number?

    The do file is the following:

    clear all
    set more off

    set seed 988

    gen random=runiform()
    by iddelemprendimiento: egen r1=max(random)
    gen ev1=1 if random==r1
    by iddelemprendimiento: egen r2=max(random) if ev1==.
    gen ev2=1 if random==r2
    by iddelemprendimiento: egen r3=max(random) if (ev1==. & ev2==.)
    gen ev3=1 if random==r3
    gen evaluaciones=1 if ev1==1 | ev2==1 | ev3==1

    collapse (mean) score if evaluaciones==1, by(iddelemprendimiento)



  • #2
    Santiago:
    welcome to the list.
    Using a limited part of your code (by the way, you probably forgot to paste the number of observations -set-), I cannot replicate the reported -seed- problem:
    Code:
    . clear all
    
    .  set more off
    
    .  set seed 988
    
    . set obs 10
    number of observations (_N) was 0, now 10
    
    .  gen random=runiform()
    
    . su
    
        Variable |        Obs        Mean    Std. Dev.       Min        Max
    -------------+---------------------------------------------------------
          random |         10    .5739065    .3332505   .0470875   .9869751
    
    . drop _all
    
    . clear all
    
    .  set more off
    
    .  set seed 988
    
    . set obs 10
    number of observations (_N) was 0, now 10
    
    .  gen random=runiform()
    
    . su
    
        Variable |        Obs        Mean    Std. Dev.       Min        Max
    -------------+---------------------------------------------------------
          random |         10    .5739065    .3332505   .0470875   .9869751
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Thanks Carlo for the reply.

      I have 1,567 observations. I am also attaching the ranking the first time I run the do file and the ranking when I run it for the second time. As you can see, the order changes and I do not know why

      Click image for larger version

Name:	Random1.jpg
Views:	1
Size:	30.6 KB
ID:	1391169

      Click image for larger version

Name:	Random2.jpg
Views:	1
Size:	29.7 KB
ID:	1391170

      Comment


      • #4
        Santiago:
        -as per FAQ, posting screenshots id pointless, as tehy are difficult to read and impossible to comment on; please, use CODE delimiters instead (# key among the options of the Advanced editor);
        -starting off from the basics, is your version of Stata fully updated?
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          Just as a side note to Carlo's helpful advices in #2 and #4, you may wish to post command as well as data, as you did in #1, but sharing an example which other members can work with.

          In #1, unfortunately, there are unavailable variables, hence we cannot try to reproduce your problem.

          Anyway, I suspect the issue may be related to the - gen - and - egen - commands you typed after creating the random numbers.
          Best regards,

          Marcos

          Comment

          Working...
          X