Announcement

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

  • Calculating trimmed mean

    I am trying to calculate trimmed mean values, where the largest and smallest 5% of returns are eliminated, in order to remove outliers from my dataset. Can anyone suggest how to go about doing this? Stata doesn't recognise the trimmean command. Thanks, Dylan

  • #2
    Stata doesn't recognise the trimmean command
    😊😊😊

    That's because Stata is not Excel and uses different language for commands.
    Btw, technically treammean is not a command, but a function.

    Code:
    sysuse nlsw88, clear
    
    centile hours , c(5 95)
    summarize hours if inrange(hours, `r(c_1)', `r(c_2)')
    
    summarize hours // for all - for comparison
    Highlighted lines calculate the mean removing 10% of the data (5% of the smallest and 5% of the largest).
    If you don't have any ties, missings, etc this is probably all that is required.

    Comment


    • #3
      Removing outliers is not what a trimmed mean does. It just ignores values as specified in the tail(s) of a distribution. Any ignored values remain in the dataset.

      trimmean (Stata Journal) is a community-contributed command. As such, you must install it before you can use it.

      Code:
      search trimmean, sj
      should open a viewer window and clicking on
      st0313 will start installation. Or you can install it from SSC, using

      Code:
      ssc install trimmean


      At the time of writing, it's the same code and essentially the same help file. at the Stata Journal and SSC sites.

      EDIT I didn't see Sergiy Radyakin's post before. But I can assure everyone that trimmean is a command, as documented above.

      I don't know of any
      treammean() function.
      Last edited by Nick Cox; 19 Aug 2020, 19:12.

      Comment


      • #4
        I think that Sergiy Radyakin was refering to an Excel function with the name treammean() and not a Stata function.

        Comment


        • #5
          Sven-Kristjan Bormann That comment led me to Google and find that Excel does have a TRIMMEAN() function. It's still a guess whether Dylan Gadhia was trying to apply similar syntax in Stata as #1 didn't show any syntax.

          This is, as you will appreciate, precisely why we have lots of detailed advice in the FAQ, including showing the code you tried. https://www.statalist.org/forums/help People who think they're too busy to read and act on it often find that good answers arrive slowly and painfully, if at all.

          Comment


          • #6
            Originally posted by Sven-Kristjan Bormann View Post
            I think that Sergiy Radyakin was refering to an Excel function with the name treammean() and not a Stata function.
            Exactly. Since the topic starter didn't clarify what treammean() (s)he wanted, and the Excel function popped out as the most prominent result.

            The code that I posted matches the example from the Excel documentation:

            Code:
            clear
            input x
            4
            5
            6
            7
            2
            3
            4
            5
            1
            2
            3
            end
            centile x, c(10 90)
            summarize x if inrange(x, `r(c_1)', `r(c_2)')
            Code:
                Variable |        Obs        Mean    Std. Dev.       Min        Max
            -------------+---------------------------------------------------------
                       x |          9    3.777778    1.394433          2          6
            With radio silence from the topic starter it's anybody's guess what was meant indeed.

            Best, Sergiy

            Comment


            • #7
              Sergiy Radyakin I share your frustration, but again no treammean() is in sight any where but in your posts. I've taken a strong interest in trimmed means and their literature and I've never seen the term treammean used anywhere for anything, although perhaps something like that is in use in Russian or some related language.

              Dylan Gadhia did "like" my post, but at most the person whose post is liked knows who did the liking. If a "like" is intended as thanks, then the thanks are private.

              https://www.statalist.org/forums/help#closure

              16. How should I maintain threads I start?

              16.1 Close by giving a summary and thanks

              Trying to wrap up a thread you started is helpful, especially if you report what solved your problem. You can then thank those who tried to help. Conversely, ignoring answers is less sociable, even if those answers did not solve your problem. "Thanks in advance" does not absolve you from either expectation.

              Please note that a Like on a post is not publicly visible as coming from you and, while friendly, also does not absolve you from either expectation.



              Comment


              • #8
                The correct spelling of the function is trimmean() in Excel. https://support.microsoft.com/en-us/...a-63d988f511d3
                Regards
                --------------------------------------------------
                Attaullah Shah, PhD.
                Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
                FinTechProfessor.com
                https://asdocx.com
                Check out my asdoc program, which sends outputs to MS Word.
                For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

                Comment

                Working...
                X