Announcement

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

  • #16
    However, I do not want certain variables to be prioritized and conditions to be applied sequentially.

    I want the conditions to apply to all variables individually.

    Is this possible at all? Maybe by first replacing the different values within a group variable by variable, and only then combining the observations?

    Comment


    • #17
      You will need to determine the max of all other variables first, e.g., by generating a variable.

      Code:
      local all_others "x1 x2 x3 x4"
      egen xmax = rowmax(`all_others')
      by entity year firm, sort: gen freq = _N
      gsort entity year -freq -xmax
      by entity year: keep if _n == 1
      If this does not answer your question, provide a data example as you did in #10 showing an initial and final dataset.

      Comment


      • #18
        I want to obtain only one observation per combination of entity and year.

        For the variable "firm", I want the most frequent value within the combination of entity and year to be chosen (to represent the former group of observations in the now single observation). If there is a tie, choose the first value within the group.
        For the variable "turno", I want the most frequent value, if there is a tie, choose the highest value (max).
        For the variable "dom", I want the most frequent value, if there is a tie, choose value 1 over value 0 (in this case max).

        For all remaining variables (not shown in the example), choose the first value within the gruop (firstnm).

        This is my original data:
        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input byte entity int year str1 firm turno dom
        1 2010 "A" 15 0
        1 2010 "B" 8 0
        1 2010 "B" 12 0
        2 2011 "A" 25 0
        2 2011 "A" 8 1
        2 2011 "A" 7 0
        3 2010 "A" 12 1
        3 2010 "B" 5 1
        3 2010 "B" 12 1
        3 2010 "A" 8 1
        end
        
        sort entity year
        list, sepby(entity year)
        and I want to achieve this result:
        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input byte entity int year str1 firm turno dom
        1 2010 "B" 15 0
        2 2011 "A" 25 1
        3 2010 "A" 12 1
        end
        
        sort
        entity year
        list, sepby(entity year)
        Last edited by rezza cav; 10 Aug 2022, 04:30.

        Comment

        Working...
        X