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 on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: transforming observations


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: transforming observations
Date   Tue, 21 Feb 2012 14:54:36 +0000

Your example is a little fuzzy. What is it that you already have, x or
temp or both?

But you can create a new variable like this

gen x = cond(temp <= 0, 0, cond(temp == 30, 1, temp))

To do this for several variables use a -foreach- loop.

Nick

On Tue, Feb 21, 2012 at 2:46 PM, Mintewab Bezabih
<Mintewab.Bezabih@economics.gu.se> wrote:

> I need to transform observations in my dataset (3476 obervations by 40 variables) into categorical variables based on the following set of rules :
>
> observation x=0 if temp<=0
> observation x=1 if temp==30
> observation x=x if temp>=31
>
> As you could imagine it would take me ages to do that one by one. Is there a compact way of doing this?
>
> Many thanks in advance
> minti
> *
> *   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/

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