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

# Re: st: alphabet range

 From Eric Booth To Subject Re: st: alphabet range Date Tue, 28 Sep 2010 08:00:52 -0500

```<>

***********************!
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
}
}
***********************!

- Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
ebooth@ppri.tamu.edu
Office: +979.845.6754

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/
```