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

st: RE: identifying rounded numbers


From   "Nick Winter" <[email protected]>
To   <[email protected]>
Subject   st: RE: identifying rounded numbers
Date   Fri, 7 Jun 2002 13:51:23 -0400

How about:

	. generate rounded1 = ((int(wage/10)*10) == wage) if wage != .
	. generate rounded2 = ((int(wage/100)*100) == wage) if wage != .

How this works:

The stuff between the first equal sign and the -if- is an expression
that evaluates to one or zero.  It evaluates to one (ie, 'true'), if
(int(wage/10)*10) equals wage, which will be the case only when the
final digit of wage is zero.

The -if wage!=.- ensures that the rounded variable is not assigned for
cases where wage is missing.

--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: Anja Decressin [mailto:[email protected]] 
> Sent: Friday, June 07, 2002 1:44 PM
> To: Statalist@Hsphsun2. Harvard. Edu
> Subject: st: identifying rounded numbers
> 
> 
> Dear Statalist,
> I have wage data and would like to identify if an observation has been
> rounded.
> I would like to know if a number has been rounded with regard 
> to the last
> digit and the last two digit.
> 
> obervation number		wage	"last digit rounded"	
> "last two digit rounded"
> 1. 				500	yes			
> 	yes
> 2.				1441	no			
> 	no
> 3.				1450	yes			
> 	no
> 
> Is there a way to identify if a number is an integer? Then I 
> could just
> divide it by 10 or 100 and check if it is an integer.
> 
> I could alsp try to make a string variable out of the "wage"-value
> (using -decode(wage),gen(strwage)- would require me to create 
> labels for the
> values, probably through some loop), counting the length of the string
> (through -length(s)-), and then using -index(strwage,"0")- 
> and the length(s)
> value to find the 0s.
> This seems way too complicated.
> 
> I guess, I could program a loop
>    	gen round10=.
> 	program define rounded10
> 	  local i=1
> 	  while`1' <=1000 {
> 		replace round10=1 if wage=i
> 		local i=`i' +1
> 		}
> 	end
> 
> but there must be Stata command for this?!
> 
> Anja Decressin (Ph.D.)
> Georgetown University
> http://www.georgetown.edu/users/decressa/
> [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/



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