Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Add


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: Add
Date   Mon, 15 Feb 2010 19:33:07 +0000 (GMT)

--- On Mon, 15/2/10, Tiago Fonseca <[email protected]> wrote:
> I have a 5 digits code and I want to generate 6 digits code
> where the last digit is:
> 0 if the 5 digits number end at 0 or a even number
> 5 if the 5 digits number end in a even number.

*-------------------- begin example ---------------------
// create some example data
clear all
set obs 10
gen long number = floor(100000*runiform())

// create your second variable
gen long number2 = 10*number + cond(mod(number,2),5,0)

// view the result
list
*--------------------- end example ----------------------
( For more on how to use examples I sent to statalist see:
 http://www.maartenbuis.nl/stata/exampleFAQ.html )

Also see: Nick Cox (2007) Stata tip 43: Remainders, 
selections, sequences, extractions: Uses of the modulus.
The Stata Journal, 7(1):143--145.
http://www.stata-journal.com/article.html?article=pr0031

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://www.maartenbuis.nl
-------------------------- 


      

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index