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
Maarten Buis <[email protected]>
To
[email protected]
Subject
Re: st: Adding "if group==1" option to a short program -- or ",by(group)"
Date
Tue, 2 Jul 2013 10:11:35 +0200
On Tue, Jul 2, 2013 at 9:51 AM, Marta García-Granero wrote:
> I have written this short program:
<snip>
> 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)
For allowing the -if- condition see: -help syntax-, for making the
program byable, see -help byable-. Below is an example. In addition to
the -if- condition I also allow the -in- condition. I also store the
statistics in more precise scalar rather than locals and I returned
the results in r(sk2) and r(kr2).
*------------------ begin example ------------------
clear all
program skr2, byable(recall) rclass
version 12.1
syntax varname [if] [in]
marksample touse
tempname sk2 kr2
_pctile `varlist' if `touse', nquantiles(8)
scalar `sk2'=(r(r6)+r(r2)-2*r(r4))/(r(r6)-r(r2))
scalar `kr2'=(r(r7)-r(r5)+r(r3)-r(r1))/(r(r6)-r(r2)) - 1.2333
display as txt "Bowley's skewness [-1; 1]: " _c
display as result %6.2f `sk2'
display as txt "Moor's kurtosis [-1.23; inf.]: " _c
display as result %6.2f `kr2'
return scalar sk2 = `sk2'
return scalar kr2 = `kr2'
end
sysuse auto
skr2 price
skr2 price if foreign == 0
bys foreign: skr2 price
*------------------- end example -------------------
* (For more on examples I sent to the Statalist see:
* http://www.maartenbuis.nl/example_faq )
---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany
http://www.maartenbuis.nl
---------------------------------
*
* 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/