Announcement

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

  • Averaging with a condition while generating a new variable

    Hi there!

    I have household-level data with unique household_id. For each household, I have data for village_id and income, among other variables.

    Is there any way I can create a new variable called village_income_mean by averaging the income amounts across a village given by village_id?

    Thanks!

  • #2
    Something like the following would do what you want.
    Code:
    by village_id, sort: egen village_income_mean = mean(income)

    Comment


    • #3
      Thanks a ton, William, it works! Also, any way I can create a variable with the standard deviation of income by village?

      Comment


      • #4
        The output of help egen lists all the functions that the egen command includes.

        Comment

        Working...
        X