Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Re: Re: st: pick maximum,minimum, mode and median among scalars
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: Re: Re: st: pick maximum,minimum, mode and median among scalars
Date
Thu, 11 Aug 2011 00:51:56 +0100
With the most common definition of the median, as you will recall, the
median is the average of two values whenever the number of values is
even. Therefore, the median is often itself _not_ one of the data
values, and so a median index is not always defined. Within continuous
data not too coarsely recorded, this will, I guess, happen about half
the time. That is one good reason for the lack of a median index
function.
By the way, the concept of minimum index or maximum index is also
problematic whenever there are ties for minimum or maximum.
Nick
On Thu, Aug 11, 2011 at 12:40 AM, Zhi Su <[email protected]> wrote:
> Dear Tirthankar,
>
> Thanks for the codes. It is a good ideas to build the constraint
> number into matrix. The codes work for getting max, min and their
> indexes.
> I are still having trouble in getting index for the median. Mata has
> function "maxindex" to get the index of maximum. And I check the
> manual of Mata,it does not have a function for median index. I just
> started to learn Mata two months ago. Therefore, I am not very
> familiar with language of Mata.
> How could I get index for median?
> Thanks a lot!
> Su
>
> From Tirthankar Chakravarty <[email protected]>
> To [email protected]
> Subject Re: Re: Re: st: pick maximum,minimum, mode and median among scalars
> Date Wed, 10 Aug 2011 14:05:37 -0700
>
> --------------------------------------------------------------------------------
>
> Nick has answered the first part of the question.
>
> The extension you seek is an application of the code I sent you
> yesterday. I leave finding the numbers corresponding to the median and
> the minimum for you. If you run into difficulties, let me know.
>
> /***********************************************/
> clear*
> sysuse auto, clear
> set matsize 1200
>
> foreach n1 in 0 5 10 {
> foreach n2 in 0 5 10 {
> foreach n3 in 0 5 10 {
> foreach n4 in 0 5 10 {
>
> generate su_`n1'_`n2'_`n3'_`n4'= ///
> (`n1'*mpg)/10+(`n2'*weight)/10+ ///
> (`n3'*length)/10+(`n4'*headroom)/10
> generate price_`n1'_`n2'_`n3'_`n4'= ///
> price- su_`n1'_`n2'_`n3'_`n4'
> regress price_`n1'_`n2'_`n3'_`n4' ///
> turn displacement gear_ratio foreign, robust
> mat mBeta= (nullmat(mBeta) \ e(b))
> mat mN = (nullmat(mN)\ (`n1', `n2', `n3', `n4'))
>
> }
> }
> }
> }
> local matcolnames: colnames mBeta
> mat colnames mN = n1 n2 n3 n4
> local matcolnames2: colnames mN
> mat mA = (mBeta, mN)
> matlist mA
>
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/