Announcement

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

  • group command in stata

    Can anyone explain what this command is doing.

    egen momid = group(v001 v002 v003)

    where

    v001 cluster number
    v002 household number
    v003 respondent's line number


    Thanks



  • #2
    This will give a unique number to all observations that have the same combination of cluster, household, and respondent line numbers. It can be used as an identifier for a group defined by common values of those three underlying variables.

    The numbers are positive integers starting with 1.

    Comment


    • #3
      group() is here a function of the egen command, and not itself a command.

      You don't give a data example, but here is a worked example, showing results with the groups command from the Stata Journal. That is quite separate and just a convenience to show what is going on, namely sorting by the variable(s) mentioned, assigning integers 1 up to the distinct groups of observations found, and optionally supplying value labels. See the help for other options. such as for including missing values.



      Code:
      . sysuse auto, clear
      (1978 automobile data)
      
      . egen group1 = group(foreign rep78)
      (5 missing values generated)
      
      . egen group2 = group(foreign rep78), label
      (5 missing values generated)
      
      . groups foreign rep78 group1 group2
      
        +----------------------------------------------------------+
        |  foreign   rep78   group1       group2   Freq.   Percent |
        |----------------------------------------------------------|
        | Domestic       1        1   Domestic 1       2      2.90 |
        | Domestic       2        2   Domestic 2       8     11.59 |
        | Domestic       3        3   Domestic 3      27     39.13 |
        | Domestic       4        4   Domestic 4       9     13.04 |
        | Domestic       5        5   Domestic 5       2      2.90 |
        |----------------------------------------------------------|
        |  Foreign       3        6    Foreign 3       3      4.35 |
        |  Foreign       4        7    Foreign 4       9     13.04 |
        |  Foreign       5        8    Foreign 5       9     13.04 |
        +----------------------------------------------------------+
      
      .

      Comment

      Working...
      X