Statalist


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

Re: st: can I do gen v1=v2=0 ?


From   Neil Shephard <nshephard@nhs.net>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: can I do gen v1=v2=0 ?
Date   Thu, 11 Sep 2008 09:19:56 +0100

Ashim Kapoor wrote:
Hi guys!

is there a command by which I can do gen v1=v2=v3=0 in stata?

A modification which may work ?
Not as far as I'm aware, its invalid syntax.

What is it that you are trying to achieve? If its simply to generate three variables which are all zero then its simply...

gen v1 = 0
gen v2 = 0
gen v3 = 0


or

forval x = 1/3{
gen v`x' = 0
}

Its not much more typing for either of these, but if you want to generate more than three variables the later is naturally extensible.

What you will find is that you can do something like....

gen v1 = v2 == v3

..which on the face of it may appear similar to what you originally wrote, but in actual fact generates v1 as a binary variable taking values of 0 and 1. If the values of v2 and v3 are equal then the test for equality is "True" or 1, if they are not equal then the test for equality is "False" or 0.

Neil

***********************************************************************
This message may contain confidential and privileged information.
If you are not the intended recipient you should not disclose, copy
or distribute information in this e-mail or take any action in reliance
on its contents. To do so is strictly prohibited and may be unlawful.
Please inform the sender that this message has gone astray before
deleting it. Thank you.

2008 marks the 60th anniversary of the NHS. It's an opportunity to pay
tribute to the NHS staff and volunteers who help shape the service, and
celebrate their achievements.

If you work for the NHS and would like an NHSmail email account, go
to: www.connectingforhealth.nhs.uk/nhsmail
***********************************************************************

*
* 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   |   What's new   |   Site index