Announcement

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

  • Adaptation of Bysort command

    Hello all,

    Is it possible in Stata to operate on only a certain subgroup of your data set while only sorting on one specific variable? By this I mean something along the lines of:

    by var1 var2 var3, sort(var4): gen wanted= var1/var2

    Those someone know if this is possible?

  • #2
    No. Stata needs to have var1, var2, and var3 sorted in order to efficiently create groups defined by them.

    If you want to preserve the original sort order of your data after a -by- command, you probably have to do something like -gen long sort_order = _n- before and then -sort sort_order- after.



    Comment


    • #3
      Further to Clyde's helpful response, the use case you show doesn't need sorting or by-group processing at all. Simply do:

      Code:
      gen wanted = var1/var2

      Comment


      • #4
        Alright thank you Clyde for your response

        Comment

        Working...
        X