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

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: can I do gen v1=v2=0 ? |

Date |
Thu, 11 Sep 2008 12:42:54 +0100 |

Such syntax, allowed in several programming languages before and after C++, is not allowed in Stata. My guess is that this is because very many commands allow stuff before and after = signs. To generalise the syntax to permit multiple assignments on the same line would mightily complicate the syntax, and the processing of syntax, and for what? To do what you outline on the very few occasions that one wants it. Setting several variables to the same value is perhaps natural when you wish to initialise a bunch of variables for later processing. Even if that is the problem the way to do it is via a loop, as Neil explained clearly. You can do this in Mata where not only do the complications of Stata not arise but also it is more natural and much more frequently a good idea. Nick n.j.cox@durham.ac.uk Ashim Kapoor I was wondering if the C++ type of assignment ( a= b = c ) works in stata. I don't think so after reading your email / testing it out in stata, but thank you for your comments. Neil Shephard > Ashim Kapoor wrote: > > > > 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. * * 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/

**References**:**st: can I do gen v1=v2=0 ?***From:*"Ashim Kapoor" <ashimkapoor@gmail.com>

**Re: st: can I do gen v1=v2=0 ?***From:*Neil Shephard <nshephard@nhs.net>

**Re: st: can I do gen v1=v2=0 ?***From:*"Ashim Kapoor" <ashimkapoor@gmail.com>

- Prev by Date:
**st: RE: per standard deviation change** - Next by Date:
**Re: st: RE: marksample** - Previous by thread:
**Re: st: can I do gen v1=v2=0 ?** - Next by thread:
**st: RE: RE: Automatically generate table with t-stat for differences inmeans** - Index(es):

© Copyright 1996–2016 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |