Announcement

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

  • median value in STATA

    Dear Statalist,

    Is it possible to get MEDIAN value in STATA. For example I want to know Median weight or age of adults of my survey population. May I know how can I get it.

    Thank you !

  • #2
    Hello Rumana,

    You can use

    Code:
    sum age, d
    I hope this helps

    Comment


    • #3
      This command gives mean only.
      But I am looking for MEDIAN.

      Thank you

      Comment


      • #4
        It gives more than the mean. Make sure you add the detail:

        Code:
        sum age, detail
        The median is basically your 50% Percentile

        You can also use:

        Code:
         
         univar age
        Mdn is your Median

        If the univar code is not installed in your stata, you can simply copy this code and paste it in your command:

        Code:
         ssc install univar
        Good luck

        Comment


        • #5
          Try -tabstat-.

          Code:
          tabstat varlist, stats(n mean median min max)

          Comment


          • #6
            Thank you so much! These are very helpful!

            Comment


            • #7
              As Saad noted, summary x, d gives the mean as the 50th percentile. You can access it if you need it using r(p50). Egen will also calculate medians and will do it by subgroups so if you need a variable with the median, egen is easier.

              Comment


              • #8
                Phil intended to say

                median as the 50th percentile.

                Comment


                • #9
                  Originally posted by Saad Al View Post
                  It gives more than the mean. Make sure you add the detail:

                  Code:
                  sum age, detail
                  The median is basically your 50% Percentile

                  You can also use:

                  Code:
                  univar age
                  Mdn is your Median

                  If the univar code is not installed in your stata, you can simply copy this code and paste it in your command:

                  Code:
                  ssc install univar
                  Good luck
                  Sir, when I am trying to install this program (ssc install univar) I am getting below error. Please advise.


                  . ssc install univar
                  checking univar consistency and verifying not already installed...
                  could not copy http://fmwww.bc.edu/repec/bocode/u/univar.hlp
                  (no action taken)
                  --Break--
                  r(1);

                  Comment


                  • #10
                    Ankit:
                    is your copy of Stata fully updated?
                    Kind regards,
                    Carlo
                    (StataNow 18.5)

                    Comment


                    • #11
                      #4 mentioned installation from SSC.

                      FWIW the SSC version of univar was superseded by an update in the Stata Technical Bulletin in 1999.

                      It's a little elusive unless you know what you're looking for --- a search univar finds several false positive hits on univariate -- but typing this command will give a clickable link:

                      Code:
                      . search sg67.1, entry historical
                      
                      Search of official help files, FAQs, Examples, and Stata Journals
                      
                      STB-51  sg67.1  . . . . . . . . . . . . . . . . . . . . . . . Update to univar
                              (help univar if installed)  . . . . . . . . . . . . . .  J. R. Gleason
                              9/99    pp.27--28; STB Reprints Vol 9, pp.159--161
                              improvements and new options to univar

                      Comment


                      • #12
                        Originally posted by Carlo Lazzaro View Post
                        Ankit:
                        is your copy of Stata fully updated?
                        Yes sir it is updated

                        Comment


                        • #13
                          Originally posted by Nick Cox View Post
                          #4 mentioned installation from SSC.

                          FWIW the SSC version of univar was superseded by an update in the Stata Technical Bulletin in 1999.

                          It's a little elusive unless you know what you're looking for --- a search univar finds several false positive hits on univariate -- but typing this command will give a clickable link:

                          Code:
                          . search sg67.1, entry historical
                          
                          Search of official help files, FAQs, Examples, and Stata Journals
                          
                          STB-51 sg67.1 . . . . . . . . . . . . . . . . . . . . . . . Update to univar
                          (help univar if installed) . . . . . . . . . . . . . . J. R. Gleason
                          9/99 pp.27--28; STB Reprints Vol 9, pp.159--161
                          improvements and new options to univar
                          Thank you sir for the help.
                          Basically, I want to have median values along with IQR of a variable. The command "sum variable, detail" is a lot of information that I do not need. I just want to have a variable median value and IQR.

                          Comment


                          • #14
                            Originally posted by Nick Cox View Post
                            #4 mentioned installation from SSC.

                            FWIW the SSC version of univar was superseded by an update in the Stata Technical Bulletin in 1999.

                            It's a little elusive unless you know what you're looking for --- a search univar finds several false positive hits on univariate -- but typing this command will give a clickable link:

                            Code:
                            . search sg67.1, entry historical
                            
                            Search of official help files, FAQs, Examples, and Stata Journals
                            
                            STB-51 sg67.1 . . . . . . . . . . . . . . . . . . . . . . . Update to univar
                            (help univar if installed) . . . . . . . . . . . . . . J. R. Gleason
                            9/99 pp.27--28; STB Reprints Vol 9, pp.159--161
                            improvements and new options to univar
                            The SSC Univar is still working as it was installed by one of my colleagues, but he has the MP version of STATA while I have the BE version. I think this mismatch is causing the installation issue

                            Comment


                            • #15
                              Ankit:
                              you may want to consider something along the following lines:
                              Code:
                              . use "C:\Program Files\Stata18\ado\base\a\auto.dta"
                              (1978 automobile data)
                              
                              . sysuse auto.dta
                              (1978 automobile data)
                              
                              . tabstat price, stat(N p25 p50 p75)
                              
                                  Variable |         N       p25       p50       p75
                              -------------+----------------------------------------
                                     price |        74      4195    5006.5      6342
                              ------------------------------------------------------
                              
                              .
                              Kind regards,
                              Carlo
                              (StataNow 18.5)

                              Comment

                              Working...
                              X