Announcement

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

  • Collapse by mean and mode

    Hello, I am currently working with a dataset that has both continuous and dichotomous or categorical variables. I am hoping to collapse them by individual within series, but as far as I am aware, -collapse- does not take mode. Is that correct?

    So with the data below, if I did:

    Code:
    collapse(mean) var1 var2 var3 var4, by(id)
    It would work wellfor var2, which is continuous, but not for var1/var3 (which are dichotomous) or var4 (which is categorical). For those, I would ideally want to take the mode, not the mean. Does anyone have a good workaround for this?

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(var1 var2 var3 var4 id series)
    1 56 1 1 1 1
    1 45 1 2 2 1
    1 65 0 2 3 1
    1 88 1 4 4 1
    0 89 0 3 5 1
    1 52 0 1 1 2
    1 46 1 2 2 2
    1 65 0 3 3 2
    1 88 1 4 4 2
    0 89 0 3 5 2
    1 53 0 1 1 3
    1 45 1 2 2 3
    1 65 0 2 3 3
    0 88 1 4 4 3
    0 89 0 3 5 3
    end

  • #2
    See
    Code:
    help egen
    which has a mode() function.

    Comment

    Working...
    X