Bookmark and Share

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   Marta García-Granero <[email protected]>
To   [email protected]
Subject   Re: st: Adding "if group==1" option to a short program -- or ",by(group)"
Date   Tue, 02 Jul 2013 10:20:10 +0200

Many thanks to Nick and Maarten for the two elegant solutions. So much to learn yet! Stata programming is absolutely different from SPSS, and I have many wrong automatisms to get rid of.

Opps! I had not spotted the error with Moors' name (the misplace quote). I'll correct it in the class notes I give my students.

Definitely I have to order a copy of Kit Baum's book for this summer.

Thanks again!

Marta

El 02/07/2013 10:13, Nick Cox escribió:
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/


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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index