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

Re: st: Stringing an entire dataset


From   Roger Newson <[email protected]>
To   [email protected]
Subject   Re: st: Stringing an entire dataset
Date   Thu, 22 Jul 2004 14:05:05 +0100

At 20:20 21/07/2004, Mart�n Rio wrote:
I'm trying to stack several datasets. Each dataset has roughly 50 variables.
Some of these are string and some numeric. The source of my problem is that
any given variable could be numeric in one dataset and string in another.
When these two fields are stacked, Stata ignores the values of this variable
in the using dataset.

I thought that one way around this problem would be to string all variables
in the data, then stack them, and then destring those that I want to be
numeric, at the end. Can anyone think of code that would string all
variables that are not already string, keeping the same name variable names?
I have had no luck so far.
Probably you should use the -unab- command to get a list of all variables, and -confirm- to check their types. Something like:

unab allvars: *
foreach X of var `allvars' {
capture confirm numeric var `X'
if _rc==0 {
tostring `X', force replace
}
}

I hope this helps.

Roger


--
Roger Newson
Lecturer in Medical Statistics
Department of Public Health Sciences
King's College London
5th Floor, Capital House
42 Weston Street
London SE1 3QD
United Kingdom

Tel: 020 7848 6648 International +44 20 7848 6648
Fax: 020 7848 6620 International +44 20 7848 6620
or 020 7848 6605 International +44 20 7848 6605
Email: [email protected]
Website: http://www.kcl-phs.org.uk/rogernewson

Opinions expressed are those of the author, not the institution.


*
* 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