Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

st: RE: Stata commands : multiple commands in one text line is allowed

From   Pradipto Banerjee <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: RE: Stata commands : multiple commands in one text line is allowed
Date   Fri, 20 Jul 2012 10:29:05 -0500


My use for the semicolon delimiter is that long Stata codes can be hard to read when one is trying to understand "logical" blocks in a code. E.g. consider the snippet:

. merge var1 var2 using data1
. keep if _m==3
. drop _m
. sort var1 var2
. compress

To me, all these lines are part of the same block. If I rewrite it as

. merge var1 var2 using data1; keep if _m=3; drop _m; sort var1 var2; compress;

then the next time I am reading the code again (say after a month), I don't need to read & understand what I did at every step - but instead what I did at that block.

Analogously, think about a 4 year old kid who looks at a word "cat" in a book and reads "c"-"a"-"t", and then tries to think what did the daycare teach him/her about "c"-"a"-"t", and then if he/she remembers "cat", they will blurt out "oh! It's cat". As an adult, we will look at "cat" and read it as "cat". That's pretty much what I am trying to achieve by putting multiple commands on a single line.

Hope that answers my original motivation for your question.


p.s. I'm more used to Matlab

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Allan Reese (Cefas)
Sent: Friday, July 20, 2012 9:54 AM
To: [email protected]
Subject: st: Stata commands : multiple commands in one text line is allowed

>> On Thu, Jun 28, 2012 at 11:18 AM, Pradipto Banerjee asked:
Is there a way in Stata to define ";" to interpret a carriage return?
>> For example, in my ado or do codes, I would like to write in a single line
>>    by xxx: gen yyy=zzz ; by xxx1: gen yyy1=zzz1 ; by xxx2: gen yyy2=zzz2

On Thu, Jun 28, 2012 at 11:40 AM, Richard Herron suggested:
> Try -#delimit ;- to get a semicolon delimiter.  -#delimit cr- to get back to the default.
> (But I guess this is different than your ultimate desire to have more
>  than one command per line, which I don't think can be done.)

I thought the same as Richard but Kreshna Gopal has put me right.  I can find no mention of this on the list or in documentation, where #delimit is described for the facility to split a long command over several lines.  And I think we are all brainwashed to think that of a Stata command as a line.

However, within a DO/ADO file:

#delimit ;
set obs 10; g x=1; g y=2; list ;

works and so does this, though this example seems very bad style!

* This line is comment ; di "Fooled you!" ;

The main use I see is to pack several short assignments on one line so the vertical blocking in the text is more visible in a screen window; it doesn't appear to save measurable time or storage space.


*   For searches and help try:

 This communication is for informational purposes only. It is not intended to be, nor should it be construed or used as, financial, legal, tax or investment advice or an offer to sell, or a solicitation of any offer to buy, an interest in any fund advised by Ada Investment Management LP, the Investment advisor.  Any offer or solicitation of an investment in any of the Funds may be made only by delivery of such Funds confidential offering materials to authorized prospective investors.  An investment in any of the Funds is not suitable for all investors.  No representation is made that the Funds will or are likely to achieve their objectives, or that any investor will or is likely to achieve results comparable to those shown, or will make any profit at all or will be able to avoid incurring substantial losses.  Performance results are net of applicable fees, are unaudited and reflect reinvestment of income and profits.  Past performance is no guarantee of future results. All f!
 inancial data and other information are not warranted as to completeness or accuracy and are subject to change without notice.

Any comments or statements made herein do not necessarily reflect those of Ada Investment Management LP and its affiliates. This transmission may contain information that is confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is strictly prohibited. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format.

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index