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

st: Better solution - tabulation of variables


From   "Nick Winter" <[email protected]>
To   <[email protected]>
Subject   st: Better solution - tabulation of variables
Date   Mon, 23 Sep 2002 11:58:14 -0400

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.

Nick



-----------------------------------------------------------
 Nicholas Winter, Ph.D.                     P 202.939.5343
 Policy Studies Associates                  F 202.939.5732
 1718 Connecticut Avenue, NW     [email protected]
 Washington, DC 20009-1148           www.policystudies.com
----------------------------------------------------------- 

> -----Original Message-----
> From: Banya, Winston [mailto:[email protected]] 
> Sent: Monday, September 23, 2002 11:43 AM
> To: '[email protected]'
> Subject: st: RE: RE: RE: RE: tabulation of variables
> 
> 
> Thanks Nick. It seems to work but some of the variables are 
> not numeric and
> so when I took that into account I am geeting an error message.
> 
> I wrote in  the last line you sent me: list 'v2' if 'v1'==. | 
> 'v1'=="&" and
> then the error message was that 'v1'is an invalid name. Note 
> the in this
> database the missinbg value for a string variable is 
> designarted as &. How
> can I modify it ?
> 
> Winston
> 
> -----Original Message-----
> From: Nick Winter [mailto:[email protected]]
> Sent: 23 September 2002 16:23
> To: [email protected]
> Subject: st: RE: RE: RE: tabulation of variables
> 
> 
> Unless I'm misunderstanding, then my code will do it for you.  Calling
> your variables v1 to v50:
> 
> 	foreach v1 of varlist v4-v50 {
> 		foreach v2 of varlist v1 v2 v3 {
> 			tab `v2' if `v1'==.
> 		}
> 	}
> 
> It is not one line, but it is pretty quick and easy to do.
> 
> If you actually want the cases listed, rather than tabulated, just
> substitute "list" for "tab" above.
> 
> If you want to list all three of the variables v1 v2 v3, then:
> 
> 	foreach v1 of varlist v4-v50 {
> 		list v1 v2 v3 if `v1'==.
> 	}
> 
> --Nick Winter
> 
> -----------------------------------------------------------
>  Nicholas Winter, Ph.D.                     P 202.939.5343
>  Policy Studies Associates                  F 202.939.5732
>  1718 Connecticut Avenue, NW     [email protected]
>  Washington, DC 20009-1148           www.policystudies.com
> ----------------------------------------------------------- 
> 
> > -----Original Message-----
> > From: Banya, Winston [mailto:[email protected]] 
> > Sent: Monday, September 23, 2002 11:20 AM
> > To: '[email protected]'
> > Subject: st: RE: RE: tabulation of variables
> > 
> > 
> > Thanks Nick but I am not sure if I am getting it right. The 
> > 'd' is among the
> > variables just likje a b or c but a b and c do not have 
> > missing values and
> > in a way are unique. So imagine that my variables are 
> > labelled 1-50 and 1-3
> > do not have missing values, then starting with variable 4  to 
> > variable 50 I
> > want all the 1-3 that have missing values in variables 4 - 50 
> > but one at at
> > time in a single command. I want 1-3 listed for missing 
> > values in 4, 5, 6
> > etc one at a time.
> > 
> > Winston Banya
> > 
> > -----Original Message-----
> > From: Nick Winter [mailto:[email protected]]
> > Sent: 23 September 2002 16:12
> > To: [email protected]
> > Subject: st: RE: tabulation of variables
> > 
> > 
> > Assuming you want to do this:
> > 
> > 	tabulate a if d==.
> > 	tabulate b if d==.
> > 	tabulate c if d==.
> > 
> > for each of many variables d, the following code wil do it for you:
> > 
> > 	foreach v1 of varlist <list of 'd' variables> {
> > 		foreach v2 of varlist a b c {
> > 			tab `v2' if `v1'==.
> > 		}
> > 	}
> > 
> > Nick Winter
> > 
> > > -----Original Message-----
> > > From: Banya, Winston [mailto:[email protected]] 
> > > Sent: Monday, September 23, 2002 11:06 AM
> > > To: '[email protected]'
> > > Subject: st: tabulation of variables
> > > 
> > > 
> > > Dear All,
> > > 
> > > I am working on a dataset with several variables ( more than 
> > > 50) and I want
> > > list missing values in terms of 3 variables. For example if 
> > > variable d has
> > > missing values, then I will want to list all the a, b or c 
> > > for which d is
> > > missing. I want to issue just one command to do that for me 
> > > rather doing it
> > > for one variable at a time. Can someone please show me 
> how to do it?
> > > 
> > > 
> > > Winston Banya
> > > Care of The Elderly Section
> > > Imperial College School of Medicine
> > > Hamersmith Hospital Campus
> > > Du Cane Road
> > > London W12 0NN
> > > 
> > > Tel: (+44) 0208 383 4284
> > > Fax: (+44) 0208 383 3378
> > > Email: [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/
> > > 
> > *
> > *   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/
> > *
> > *   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/
> > 
> *
> *   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/
> *
> *   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/
> 
*
*   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