Announcement

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

  • Separate a variable in groups and apply some tests

    Hi everyone.

    I´m trying to run some tests over a dataset, but I have doubts about how to separate the data in some groups.

    For example, I have two variables one called "perc" and other called "at".

    I want to apply a t-test to compare the means of the "perc" between the group that have values of "at" below the median of all and with the other group that have the values of "at" above the median of all.

    How can I do this?

    Sicerely,

    Marcel.

  • #2
    There are probably many ways. Here is one possibility:

    Code:
    sysuse auto, clear
    
    * Gather the median
    summarize mpg, detail
    
    * Create the indicator
    generate above_med = mpg >= 20 & !missing(mpg)
    
    * t-test
    ttest price, by(above_med)

    Comment

    Working...
    X