Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: RE: rowskew?


From   Steven Samuels <[email protected]>
To   [email protected]
Subject   Re: st: RE: rowskew?
Date   Tue, 14 Oct 2008 09:17:43 -0400

Here is Matt's code with a couple of macros to reduce typing. I've subtracted 1 from the row mean and also subtracted 3 from the kurtosis formula Matt used. See: http://www.itl.nist.gov/div898/ handbook/eda/section3/eda35b.htm

-Steve

**************************CODE BEGINS**************************
sysuse auto,clear

****************************************************
* Create local macro vlist with variables to analyze
****************************************************
local vlist "mpg rep78 trunk turn"

egen rowmean = rowmean(`vlist')
egen rowN =rownonmiss(`vlist')

forvalues i=2/4{
gen m`i'=0
foreach v of local vlist {
replace m`i' = m`i' + (`v'-rowmean)^`i'
di  m`i'
}
replace m`i' = m`i'/(rowN-1)
}

** http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm **

gen rowskew = m3*m2^(-3/2)
gen rowkurt = m4*m2^(-2) -3

list `vlist' row* in 1/5
***************************CODE ENDS*******************************

On Oct 13, 2008, at 11:21 PM, Matt Spittal wrote:

jeheyman,

You can use the moments about the mean to calculate skew and kurtosis for a row of variables. Imagine that you want to do this for the variables weight, length and price from the auto dataset.

	sysuse auto, clear

	// get mean and N
	egen rowmean = rowmean(weight length price)
	egen rowN = rownonmiss(weight length price)

	// calculate 2, 3, and 4th moments about the mean
gen m2 = 1/rowN * ((weight - rowmean)^2 + (length - rowmean)^2 + (price - rowmean)^2) gen m3 = 1/rowN * ((weight - rowmean)^3 + (length - rowmean)^3 + (price - rowmean)^3) gen m4 = 1/rowN * ((weight - rowmean)^4 + (length - rowmean)^4 + (price - rowmean)^4)

	// calculate skew and kurtosis
	gen rowskew = m3*m2^(-3/2)
	gen rowkurt = m4*m2^(-2)

	list weight length price rowskew rowkurt in 1/10

-- Matt
[email protected]	

-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of jeheyman
Sent: Tuesday, 14 October 2008 12:31 PM
To: [email protected]
Subject: st: rowskew?


Is it possible to calculate essentially a rowskew and rowkurtosis in
the same way that egen calculates rowmean?

For each observation I have 18 variables and I need, obviously, the
three distribution measures.  Mean is trivial but the other two are
proving elusive. I feel like I'm overlooking something obvious and
posting seemed to be better than continuing to bang my head against
the wall.

Thanks.


*
*   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/

*
*   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/

*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index