Announcement

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

  • If varx>median(vary)

    Is it possible to use if followed by the median of a variable but using median(varname) instead of the actual number or something alike I'm making a lot of regressions tables so using the number is not that efficient in time. This is what I'm doing at the moment assuming the median of x3 is 50 reg y x1 x2 if x3>50 reg y x1 x2 if x3

  • #2
    his is what I'm doing at the moment assuming the median of x3 is 50 reg y x1 x2 if x3>50 reg y x1 x2 if x3

    Comment


    • #3
      There is no median() function that can be used in an if qualifier. However, you can create a variable that contains the median and use that:

      Code:
      egen med_x3=median(x3)
      regress y x1 x2 if med_x3>50
      Please note in the FAQ the Statalist preference for using your full name.

      Comment


      • #4
        Are you wanting a way to get at the median programmatically so you can use it over and over like in a loop? You might want something like:
        Code:
        foreach var of varlist id-qu5 {
        qui sum `var', det
        local medvar=r(p50)
        disp "regression with `var' >50pct = `medvar'"
        reg qu1 sex age qu2 qu3 qu4 qu5 if `var'>`medvar'
        }
        Last edited by ben earnhart; 19 Dec 2014, 11:02.

        Comment

        Working...
        X