Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: Can you get sign of value only?


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: Can you get sign of value only?
Date   Thu, 23 Mar 2006 23:27:44 -0000

Note that the difference between this and using -sign(y)- 
is that -sign(0)- is 0. 

A quite different point is that there is another way 
to write what Jennifer is suggesting, namely 

gen z = cond(y < 0, -x, x) 

Nick 
n.j.cox@durham.ac.uk 

Marino, Jennifer
 
> Maybe I'm not understanding, but couldn't you just do this?
> 
> gen z = x
> replace z = x*(-1) if y<0

Danielle H. Ferry

> Is it possible to get the sign of a value? I.e., I would like to
> multiply the var x by either -1 or +1 depending on the sign of var y.

*
*   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–2020 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index