Bookmark and Share

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


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

Re: st: More elegant code . . .?


From   Eric Booth <[email protected]>
To   "<[email protected]>" <[email protected]>
Subject   Re: st: More elegant code . . .?
Date   Sun, 5 Jun 2011 01:04:16 +0000

<>

Here are 2 examples:
*************************!
**replace & inlist**
h inlist
g letter_auto_stop = 0
replace letter_auto_stop = 1 if inlist(1, letter1, letter2, letter3, letter4, letter5, letter6, letter7, letter8, letter9, letter10)

**loop**
g letter_auto_stop2 = 0
forval n = 1/10 {
	replace letter_auto_stop2 = 1 if letter`n' == 1
	}
*************************!
^watch for line wrapping in the code above

- Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]


	
	
On Jun 4, 2011, at 6:18 PM, Michael Costello wrote:

> Statalisters,
> 
> I have some code that I would like to make more elegant (shorter,
> while still fitting on one line):
> recode letter_auto_stop 0=1 if letter1==0 & letter2==0 & letter3==0 &
> letter4==0 & letter5==0 & letter6==0 & letter7==0 & letter8==0 &
> letter9==0 & letter10==0
> 
> The line above works, but it's bulky.  I'd like to find something
> better to use.  I tried:
> recode letter_auto_stop 0=1 if letter1-letter10==0
> 
> but stata treated it as "recode letter_auto_stop 0=1 if letter1==0 &
> letter10==0" ignoring letter2 through letter9 entirely.
> 
> Thanks for any help you can provide!
> -Michael
> 
> --
> Michael Costello
> Mathematics & Statistics Teacher, Bethesda-Chevy Chase High School
> Intern, RTI International
> 
> "To call in the statistician after the experiment is done may be no
> more than asking him to perform a post-mortem examination: he may be
> able to say what the experiment died of."  -Sir Ronald Aylmer Fisher,
> FRS
> 
> *
> *   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index