Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: Add


From   Maarten buis <maartenbuis@yahoo.co.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Add
Date   Mon, 15 Feb 2010 19:33:07 +0000 (GMT)

--- On Mon, 15/2/10, Tiago Fonseca <tiago.p.fonseca@gmail.com> 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index