Announcement

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

  • How can I compute quintiles on a higher group-level using xtile?

    Suppose the dataset contains a subject-specific variable "earnings". All subjects are grouped into groups, let's say industries. How can I now use xtile to split my data into quintiles on the (higher) industry level? As an example, suppose 1.564 workers work in 20 different industries - in the end, there should be 4 industries in each quintile based on the average earnings within these industries (no matter how many workers are in each industry).

  • #2
    Lacking sample data to work with, I'll reply in kind and suggest the following untested sequence of tasks, with code that may or may not accomplish what the task description says.

    First, create a new variable containing mean earnings by industry, something like
    Code:
    bysort industry: egen indearn = mean(earnings)
    Next, identify one observation per industry
    Code:
    bysort industry: generate indobs = _n==1
    (This could also be accomplished using the tag() function with egen.)

    Use these observations with xtile
    Code:
    xtile xt1 = indearn if indobs, nquantiles(5)
    Now copy these values to all observations in the industry
    Code:
    bysort industry: egen xt = max(xt1)

    Comment

    Working...
    X