Announcement

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

  • #16
    to Question in #15
    Variables 46
    Obs 23'465'605
    size 2'616'052M. I run the first line again when posting, still not finished
    Last edited by Da GXHI; 25 May 2022, 12:29.

    Comment


    • #17
      egen is not very fast but on a very mundane laptop this script took about 1 minute to finish. Using Stata 17. Note that most of it is setting up an example dataset, which you don't need to do.

      Code:
      clear 
      set rmsg on 
      set obs 24000000
      egen year = seq(), block(1000000)
      set seed 2803 
      gen place = runiformint(1, 1000)
      gen id = runiformint(1, 1000)
      
      egen tag = tag(place id year)
      egen distinct = total(tag), by(place year)

      Comment


      • #18
        Thanks. What I do is very much the same, just that my id variable is string and my place variable is dummy (1/0). I will give it another try,
        Any known reason way tag function may not wor as well with stat 15.1? I am reluctant on updating the stata version as the rest of my code might be affected.

        Comment


        • #19
          Sorry, but I don't know why this calculation should take hours, as you imply.

          Comment


          • #20
            use dataset.dta, clear

            egen tag_firm = tag(cocode year PC)
            egen distinct_firm = total(tag_firm), by(year PC)

            *cocode is a string, year is floating, PC is dummy
            just n case you see something I don't

            Comment


            • #21
              I have the same question, but a bit different. I have a variable (Companies: NPC_FIC), some are repeated and some are not. Because more often firms have more than one worker in this case Company's ID appears more than once. I need to compute SUM ( observation, mean, std.dev. min and max) of firms.
              * Example generated by -dataex-. For more info, type help dataex
              clear
              input double NPC_FIC
              500000001
              500000001
              500000001
              500000002
              500000002
              500000002
              500000002
              500000002
              500000033
              500000033
              500000050
              500000050
              500000083
              500000104
              500000119
              500000119
              500000119
              500000119
              500000119
              500000119
              500000119
              500000119
              500000121
              500000121
              500000156
              500000156
              500000157
              500000157
              500000157
              500000157
              500000165
              500000165
              500000165
              500000180
              500000198
              500000198
              500000198
              500000201
              500000204
              500000204
              500000212
              500000215
              500000215
              500000215
              500000215
              500000240
              500000240
              500000276
              500000279
              500000284
              500000284
              500000284
              500000284
              500000305
              500000334
              500000341
              500000341
              500000346
              500000346
              500000346
              500000376
              500000376
              500000395
              500000395
              500000395
              500000395
              500000395
              500000395
              500000465
              500000465
              500000465
              500000470
              500000470
              500000478
              500000525
              500000543
              500000543
              500000565
              500000583
              500000633
              500000633
              500000675
              500000709
              500000748
              500000757
              500000765
              500000765
              500000765
              500000766
              500000766
              500000774
              500000791
              500000791
              500000795
              500000795
              500000795
              500000795
              500000796
              500000800
              500000800
              end
              [/CODE]
              ------------------ copy up to and including the previous line ------------------


              any ideas?

              Comment


              • #22
                Hello all,
                I am using Stata 16. In my panel data, and I have variables state and district. Each state has a certain number of districts. I want to count how many districts are there per state.

                I used the following
                Code:
                egen tag = (district state)
                followed by
                Code:
                egen distinct = total(district), by (state)
                however it gives me an error
                type mismatch

                Kindly suggest what mistake I am making here. Thank you.

                Comment


                • #23
                  Code:
                   
                   egen tag = tag(district state)

                  Comment

                  Working...
                  X