Announcement

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

  • #16
    please disregard the previous post. I found out what happened. sorry for the inconvenience.

    Comment


    • #17
      It would be a contribution to our community if you posted what you found out. You probably will not be the last person to encounter the same difficulty, and others may benefit from learning what happened in your case. Your original question was no inconvenience to anybody. Not telling what you found is.

      Comment


      • #18
        Hey, I have the identical problem. I thought setting a seed is enough to solve it. But unfortunately it didn't work. Probably since I did something wrong while setting the seed? I'd be grateful if somebody could take a look at my code below and help me out!

        Thank you!!

        HTML Code:
        use data.dta
        set seed 1
        collapse (sum) size, by(firm year)
        save test.dta
        
        use data.dta
        set seed 1
        collapse (sum) size, by(firm year)
        cf size using test.dta
        Last edited by Jonathan Mickels; 28 Jan 2025, 15:32.

        Comment


        • #19
          Using a "seed" is not the same as a "sortseed", the former is used for random number generation, and the later is used for random sort order. In either case, this can't be the solution since -collapse- will sort the data according to groups specified by the -by()- variables anyway.

          Please, if you are going to request help with code, provide us a data sample that illustrates the problem. We don't have your data.dta, so it's unhelpful for us to troubleshoot.

          In any case, the code you have present performs the same way on the same dataset so they should be identical.

          Comment


          • #20
            Hey Leonardo,

            thank you so much for your quick response. Actually, it helped me spotting my mistake. Sortseed does the trick. So the solution proposed in earlier posts works, I just didn't know that sortseed for sorting exists.

            Comment


            • #21
              Originally posted by Jonathan Mickels View Post
              Hey Leonardo,

              thank you so much for your quick response. Actually, it helped me spotting my mistake. Sortseed does the trick. So the solution proposed in earlier posts works, I just didn't know that sortseed for sorting exists.
              Thanks for closing the loop on the issue and letting us know how you solved the problem. I'd be curious if you provided a sample of your data that illustrates why sortseed matters here.

              Comment


              • #22
                Here's a replicable example of a basic collapse result dependent on sortseed:
                Code:
                clear all
                sysuse nlsw88, clear
                keep wage c_city
                recast double wage
                replace wage = wage + 1000000*wage
                expand 1000
                preserve
                set sortseed 1
                collapse (mean) wage, by(c_city)
                save "$temp_dir/collapse_test.dta", replace
                restore
                
                preserve
                set sortseed 1 // needed to replicate exactly
                collapse (mean) wage, by(c_city)
                cf _all using "$temp_dir/collapse_test.dta", verbose
                restore
                
                preserve
                collapse (mean) wage, by(c_city)
                cf _all using "$temp_dir/collapse_test.dta", verbose // fails
                restore
                Output of that last cf shows two mismatches, so close (in this case) that the displayed digits are identical, though I have seen larger differences in real-world use cases with confidential data:
                Code:
                            wage: 2 mismatches
                                  obs 1. 7599984.6 in master; 7599984.6 in using
                                  obs 2. 8172533.6 in master; 8172533.6 in using
                Stata/MP 19.0 for Windows (64-bit x86-64) - 6 core license
                Revision 28 Jan 2026

                Comment

                Working...
                X