Announcement

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

  • regression results changes every time I ran it

    Hi, everyone,
    I feel confused that each time I ran my code to generate the data and also regreesion, the regeression results changes a little bit. Not much, but always change.
    I didn't generate random numbers.

    Thanks so much if any advice could be offered. Thanks!

  • #2
    are you -sort-ing the data? if there are ties, sort will break the tie haphazardly (some might say randomly) unless you use the "stable" option; see
    Code:
    h sort
    if you are not sorting the data then you need to show the code (at least for me - maybe someone else has another guess)

    Comment


    • #3
      Originally posted by Rich Goldstein View Post
      are you -sort-ing the data? if there are ties, sort will break the tie haphazardly (some might say randomly) unless you use the "stable" option; see
      Code:
      h sort
      if you are not sorting the data then you need to show the code (at least for me - maybe someone else has another guess)
      Thanks so much, Rich!
      However, concerning "sort" code, I just used "bys city year: egen X_median = median(X) " and "bys city year: egen X_mean = mean(X) " and "bys city year: egen X_total = total(X) ".
      Would this cause any problems?

      Comment


      • #4
        Show me the regression code. There's no reason you should be getting different results each time unless you're generating random numbers and not using the same seed each time

        Comment


        • #5
          Olivia Li as requested in #2 and #4, we need to see your code, and preferably a data extract (for this, use -dataex-) and be able to replicate your issue, to figure out what's going on.

          In addition, note that you can avoid sorting your data by using -by()- as an option to your egen command, rather than using it as a prefix.

          Comment


          • #6
            Olivia:
            as an aside to previous excellent advice: do -summarize- results also change each time you run your code?
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment

            Working...
            X