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

RE: st: another data cleaning question


From   Babigumira Ronnie <[email protected]>
To   [email protected]
Subject   RE: st: another data cleaning question
Date   Mon, 24 Jun 2002 05:49:03 -0700 (PDT)

Hi Hakon
Many thanks. Both options work fine. I will go with

. replace cropcod2=int(varcode/1000) if inrange(varcode,100000,.)

Cheers

Roni
--- Finne_H�kon <[email protected]> wrote:
> Several possibilities. The easiest one now (provided there are no more
> surprises) is to add one line of code after gen
> cropcod2=int(varcode/100):
> 	replace cropcod2=int(varcode/1000) if inrange(varcode,100000,.)
> -inrange- is listed under special functions; see -help functions- .
> The following code will yield the same result:
> 	replace cropcod2=int(varcode/1000) if varcode>99999 & varcode<.
> 
> H�kon

----Original Message-----
> > From: Babigumira Ronnie [mailto:[email protected]]
> > Sent: 24. juni 2002 10:29
> > To: [email protected]
> > Subject: Re: st: another data cleaning question
> > 
> > 
> > --- Roger Newson <[email protected]> wrote:
> > > 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
> > consistent
> > > cases, and halt execution if there are any inconsistent 
> > cases, and drop
> > > the variable -cropcod2- otherwise.
> > > 
> > > I hope this helps.
> > > 
> > Hi Roger,
> > Many thanks. It works however, I have a slight complication, 
> > some of the
> > variety codes are more than 5. Here is an example (also 
> > included is the
> > new variable cropcod2)
> > 
> >         villcode  cropcode   cropcod2       varcode
> > 1.      1531002       110        110         11001
> > 2.      1531002       110        110         11001
> > 377.    1360100       110       1101        110104
> > 378.    1362000       110       1101        110104
> > 
> > The first 2 varcodes have 5 digits and hence 
> > 
> > . gen cropcod2=int(varcode/100) 
> > 
> > would work just fine, however, the last two have varcodes 
> > with 6 digits
> > which would therefore mean that I would need to rewrite the syntax to 
> > 
> > . gen cropcod2=int(varcode/1000)
> > 
> > This would however truncate that 5 digit varcodes and the resulting
> > cropcod2 would have 2 digits.
> > 
> > I would therefore like to put in a condition that would allow 
> > the first
> > truncation to be done only if the number of digits in varcode is 5 and
> > then replace cropcod2 with a new truncated figure if the varcode has 6
> > digits. I have searched the manual and I still haven't found 
> > it. Might you
> > (or anyone else reading) have any idea how I can do this.
> > 
> > Roni
> > 
> > 
> > 
> > __________________________________________________
> > Do You Yahoo!?
> > Yahoo! - Official partner of 2002 FIFA World Cup
> > http://fifaworldcup.yahoo.com
> > *
> > *   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/


__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com
*
*   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