Announcement

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

  • conditional bysort

    Hi there,
    I have a simple question on the function of bysort.
    I know that we can use it to generate sum/mean by group. Usually bysort classify groups by a variable, yet can we make it a range?
    For instance if I have data on people's calorie intake by age, gender and race. How can I know the group statistics on the group (female, white, age from 20-30)?

    Thank you!

  • #2
    I might be wrong, but I am fairly certain you need to create a variable to capture the range, then bysort by that. Which should be easy enough. Female and race don't need a recode, so all you'd need to do is a few lines (or even a single line with -recode-) to categorize age.

    Comment


    • #3
      Good idea! Thank you Ben!

      Comment


      • #4
        Ben is absolutely correct that you need to have a variable created to do this.

        I'd add that recode is not the only way to categorise finely reported variables. For example,

        Code:
         
        gen age2 = 10 * floor(age/10)
        creates 10 year wide bins.

        Comment

        Working...
        X