Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Better solution - tabulation of variables


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Better solution - tabulation of variables
Date   Mon, 23 Sep 2002 17:02:49 +0100

Nick Winter
 
> Actually, my last won't do it.  This will:
> 
> foreach v1 of varlist v4-v50 {
> 	foreach v2 of varlist v1 v2 v3 {
> 		local type : type `v1'
> 		if substr("`type'",1,3)=="str" {
> 			di
> 			di "{txt}Tabulation of `v2' for missing `v1'
> (string):"
> 			tab `v2' if `v1'=="&"
> 			di
> 		}
> 		else {
> 			di
> 			di "{txt}Tabulation of `v2' for missing `v1'
> (numeric):"
> 			tab `v2' if `v1'==.
> 		}
> 	}
> }
> 
> 
> The "local type:" line checks the variable type, then proceeds
> accordingly.

Another way to do it, implementing my last posting: 

1. Fix those "&". Better done sooner rather than later. 

foreach v of var * { 
	capture replace `v' = "" if `v' == "&" 
} 

2. Use the -missing()- function. 

foreach v1 of varlist v4-v50 {
 	foreach v2 of varlist v1 v2 v3 {
 			di
 			di "{txt}Tabulation of `v2' for missing `v1'"
 			tab `v2' if missing(`v1') 
	}
}

Nick 
[email protected] 
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index