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: st: pick maximum,minimum, mode and median among scalars
From
Tirthankar Chakravarty <[email protected]>
To
[email protected]
Subject
Re: st: pick maximum,minimum, mode and median among scalars
Date
Tue, 9 Aug 2011 15:16:08 -0700
A scalable way of doing this without the need to save individual
coefficients uses Mata (and Ben Jann's -moremata- package, SSC).
/******************************************/
clear*
sysuse auto, clear
constraint 1 price = weight
constraint 2 displacement = weight
constraint 3 gear_ratio = -foreign
constraint 4 _cons = 0
forv i=1/4 {
cnsreg mpg price weight displacement gear_ratio foreign length, c(`i')
mat mBeta = (nullmat(mBeta) , e(b)')
}
mat list mBeta
// max and min
mata: st_matrix("vBetaMax", rowmax(st_matrix("mBeta")))
mata: st_matrix("vBetaMin", rowmin(st_matrix("mBeta")))
mat list vBetaMax
mat list vBetaMin
// median (needs Ben Jann's -moremata-, SSC)
mata mata mlib index
mata: st_matrix("vBetaMed", mm_quantile(st_matrix("mBeta")', 1, .5 )')
mat list vBetaMed
/******************************************/
T
On Tue, Aug 9, 2011 at 2:52 PM, Zhi Su <[email protected]> wrote:
> Dear Statalists,
>
> I wan to get some statistics of coefficients of the same independent
> in regressions subjected to different constraints.
> For example, I run the following regression four times. Each time
> the regression is subjected to a constraint. Here is the code for
> regression in constraint 1.
>
> cnsreg y x1 x2 x3 x4,constraints(1)
> scalar b11=_b[x1]
> scalar b12=_b[x2]
> scalar b13=_b[x3]
> scalar b14=_b[x4]
> then I save the coefficients for x1, x2, x3, x4 in scalars
>
> Then I get a group of scalars:
> b11 b12 b13 b14 for the regression with constraint1
> b21 b22 b23 b24 for the regression with constraint2
> b31 b32 b33 b34 for the regression with constraint3
> b41 b42 b43 b44 for the regression with constraint4
>
> Now b11 b21 b31 b41 are all coefficients for x1. I want to determine
> which one among them is maximum,minimum, mode and median of this group
> of scalars.
> What if the number of constraints is over 100, how can I pick the
> maximum,minimum, mode and median among a group of scalars of interest?
>
> Thank you!
>
> --
> Zhi Su
> 348 Holmes Hall
> Northeastern University
> 360 Huntington Avenue
> Boston, MA 02115
> Office:1-617-373-2316
> email:[email protected]
> *
> * 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/
>
--
Tirthankar Chakravarty
[email protected]
[email protected]
*
* 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/