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]
st: by-group header in byable(onecall) programs
From
Dirk Enzmann <[email protected]>
To
[email protected]
Subject
st: by-group header in byable(onecall) programs
Date
Sun, 21 Jul 2013 13:18:03 +0200
I'm struggling with programming a by-group header in a byable(onecall)
program. Ideally it should match the header which is automatically
created when using the -byable(recall)- option of -program-, i.e. using
more than one by-variable it should be of the form
------------------------------------------------
-> var1 = label by-group var1, var2 = label by-group var2
Instead, so far I only managed to to create a header of the form
-----------------------------------------------
-> var1 var2 = label by-group var1 label by-group var2
Here is the version of a program which will create a header of the
second type (what the program does not not the issue, I know that byable
programs to center variables exist already):
* --- Begin Stata: -------------------------------
cap program drop foo
program foo, byable(onecall)
version 12.1
syntax varname(numeric) [if] [in], Generate(string)
marksample touse
tempvar bygr
if "`_byvars'" == "" {
sum `varlist' if `touse'
qui gen `generate' = `varlist'-r(mean) if `touse'
}
else {
qui egen `bygr' = group(`_byvars'), missing lname(bylab)
qui levelsof `bygr' if `touse', local(K)
qui gen `generate' = .
foreach k of local K {
di "{hline}" _n as res "-> `_byvars' = `: label (`bygr') `k''"
sum `varlist' if `touse' & `bygr'==`k'
qui replace `generate' = `varlist'-r(mean) if `touse' & `bygr'==`k'
di
}
}
end
* --- End Stata. ---------------------------------
Are there any suggestions to create a header of the first type?
Dirk
========================================
Dr. Dirk Enzmann
Institute of Criminal Sciences
Dept. of Criminology
Rothenbaumchaussee 33
D-20148 Hamburg
Germany
phone: +49-(0)40-42838.7498 (office)
+49-(0)40-42838.4591 (Mrs Billon)
fax: +49-(0)40-42838.2344
email: [email protected]
http://www2.jura.uni-hamburg.de/instkrim/kriminologie/Mitarbeiter/Enzmann/Enzmann.html
========================================
*
* 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/