Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

RE: st: alphabet range


From   Nick Cox <n.j.cox@durham.ac.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   RE: st: alphabet range
Date   Tue, 28 Sep 2010 17:28:32 +0100

For more on c(alpha) and friends, see 

SJ-4-2  pr0013  . . . . . . . . . . . Stata tip 9: Following special sequences
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q2/04   SJ 4(2):223                              (no commands)
        tip for using creturn to access special sequences stored
        as c-class values

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

Eric Booth

clear
inp  q17as q17af q18bf q18bs q22af q22as
1 2 3 4 5 6
9 9 8 8 7 7 
1 2 1 2 3 4
2 2 2 2 2 2
end


**change the forval loop to the number of questions you have**
local vlist `c(alpha)'
foreach var of local vlist {
	forval n = 1/22 {
	di "dsq`n'`var'
 cap	gen dsq`n'`var' = q`n'`var'f - q`n'`var's
}
	}

On Sep 28, 2010, at 7:27 AM, Bernie Hogan wrote:

> q17af
> 
> where 17 is the matrix, a is the row, and f is the first person to
> respond, s is the second.
> 
> I would like to be able to do calculations on the entire row. The best
> I could come up with was:
> 
> local vlist a b c d e f g h i
> 
> foreach var of local vlist {
> 	gen dsq17`var' = q17`var'f - q17`var's
> }
> 
> But that means every time I do a new matrix I have to figure out how
> many variables, and then type out their letter by hand.
> 
> What I would really like is to be able to say:
> 
> foreach var of q17? [f or s] {
> gen newvar = q17?f - q17?s
> }
> (or whatever is the closest to that)


*
*   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   |   Site index