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

Re: st: another data cleaning question


From   Roger Newson <[email protected]>
To   [email protected]
Subject   Re: st: another data cleaning question
Date   Sun, 23 Jun 2002 18:00:06 +0100

At 08:46 23/06/02 -0700, Babigumira Ronnie wrote:
Dear listers
I have data that looks like this

cropcode varcode
116      11603
115      11599
223      22309

The first variable is the code for different crops while varcode is the
specific variety. As you can see from the example, the variety code comes
from crop code (the first three digits are the crop codes).

I am cleaning the data and I would like to flash out cases where the
varcode is not consistent with the cropcode such as

cropcode varcode
116      11503
           ^
How can I do this in stata?
Use the -int- function (see -help functions-). In this case, you might type

gene cropcod2=int(varcode/100)
list if cropcod2!=cropcode
assert cropcod2==cropcode
drop cropcod2

and Stata will generate a new variable -cropcod2-, which should be equal to -cropcode- if the data are consistent. Stata will then list inconsistent cases, and halt execution if there are any inconsistent cases, and drop the variable -cropcod2- otherwise.

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]

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