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: How to create a new variable ...


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: How to create a new variable ...
Date   Thu, 5 May 2011 19:27:50 +0100

This is (almost) the remainder on dividing by 5.

gen newvar = cond(mod(oldvar, 5) == 0, 5, mod(oldvar, 5))

Incidentally I have traced the misuse of mod() or a similar name to
mean remainder back to FORTRAN in 1954. Anyone know an earlier source?

On Thu, May 5, 2011 at 7:05 PM, Alberto R Osella
<[email protected]> wrote:
> Oliver and Daniel thank you again.
> Sorry but it happened that I was quite unclear with my previous post.
> My oldvar takes on values from 1 to 306.
> Indeed I need to generate a new variable in this way:
> newvar which takes on the value 1 each time oldvar takes on the values 1, or
>  6, or 11,.....,or 301
> newvar which takes on the value 2 each time oldvar takes on the values 2, or
>  7, or 12,.....,or 302
> newvar which takes on the value 3 each time oldvar takes on the values 3, or
>  8, or 13....., or 303
> newvar which takes on the value 4 each time oldvar takes on the values 4, or
>  9, or 14,.....,or 304
> newvar which takes on the value 5 each time oldvar takes on the values 5, or
> 10, or 15,.....,or 305

*
*   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