Stata Code: describetext

version 7.0

#delimit ;

program define describetext, rclass;
    syntax varlist(min=1) [if/];
    tempvar totwords;
    if ("`if'"=="") {; local if = "ntuple>=1";};
    capture confirm variable ntuple;
    if (_rc==111) {; quietly gen ntuple = 99;};
    display in text;
    display in text "            {c |}     Ref   Total  Unique   Mean   Median   Max";
    display in text "       Text {c |}   Score   Words   Words   Freq.   Freq.  Freq.";
    display in text "{hline 12}{c +}{hline 47}";

    tokenize `varlist';
    tempvar totuniqwords;
    tempvar totuniqwords2;
    quietly gen `totwords' = 0;
    quietly gen `totuniqwords' = 0;
    quietly gen `totuniqwords2' = 0;
    while "`1'" ~= "" {;
	* display ``1'[rscore]';
 	if (index("$rtextnames", "`1'")==0 | "``1'[rscore]'"=="") {;
           char `1'[rscore] . ;};
	quietly replace `totwords' = sum(`1') if `if';
	quietly summarize `totwords' if `if', detail;
	local twords = r(max);
	quietly replace `totuniqwords'  = (`1' > 0) if `if';
	quietly replace `totuniqwords2' = sum(`totuniqwords') if `if';
	quietly summarize `1' if `totuniqwords'>0 & `if', detail;
        display in text %11s abbrev("`1'",11) " {c |}" as result
                        %8.2f ``1'[rscore]'
                        %8.0gc `twords'	
                        %8.0gc  r(N)
			%8.2f   r(mean)
                        %8.2f   r(p50) 
                        %6.0f   r(max);
	macro shift;
    };
    if (ntuple[_N]==99) {; drop ntuple;};
end;