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: Adding "if group==1" option to a short program -- or ",by(group)"
From
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: Adding "if group==1" option to a short program -- or ",by(group)"
Date
Tue, 2 Jul 2013 09:13:28 +0100
The classic guide to learning Stata programming remains the
appropriate chapters of [U]. For another excellent guide see Kit
Baum's http://www.stata.com/bookstore/stata-programming-introduction/
Try this
program skr3
version 12.1
syntax varname(numeric) [if] [in]
marksample touse
qui count if `touse'
if r(N) == 0 error 2000
_pctile `varlist' if `touse', nquantiles(8)
local sk2 = (r(r6)+r(r2)-2*r(r4))/(r(r6)-r(r2))
local kr2 = (r(r7)-r(r5)+r(r3)-r(r1))/(r(r6)-r(r2)) - 1.2333
display "Bowley's skewness [-1; 1]: " %6.2f `sk2'
display "Moors' kurtosis [-1.23; inf.]: " %6.2f `kr2'
end
Moors is the person's surname, hence Moors' (or Moors's).
Extensions to think about:
1. A minimum sample size for this to go ahead.
2. Saving results as r-class.
See also -lmoments- (SSC) for some of many alternative measures.
Nick
[email protected]
On 2 July 2013 08:51, Marta García-Granero <[email protected]> wrote:
> Good morning.
>
> I have written this short program:
>
> program skr2
> version 12.1
> args x
> confirm variable `x'
> _pctile `x', nquantiles(8)
> local sk2=(r(r6)+r(r2)-2*r(r4))/(r(r6)-r(r2))
> local kr2=(r(r7)-r(r5)+r(r3)-r(r1))/(r(r6)-r(r2)) - 1.2333
> display "Bowley's skewness [-1; 1]: " %6.2f `sk2'
> display "Moor's kurtosis [-1.23; inf.]: " %6.2f `kr2'
> end
>
> As it can be seen from its contents, it computes robust skewness and
> kurtosis coefficients for just one variable.
>
> I promise I have tried to read the documentation on programming, but I
> couldn't find how to modify it to be able to accept the selection of
> subgroups based on a second variable, like:
>
> skr2 iron if group==1
>
> or maybe
>
> skr2 iron, by(group)
>
> Any hints would be very much appreciated. I don't need the complete solution
> (I'd like to face the task and learn more about Stata programming), just a
> gentle push in the correct direction.
>
> Thanks a lot,
> Marta GG
>
>
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/