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: Use of matrix values in generate statements
From
Daniel Feenberg <[email protected]>
To
[email protected]
Subject
re: st: Use of matrix values in generate statements
Date
Sun, 27 Mar 2011 15:19:03 -0400 (EDT)
On Sun, 27 Mar 2011, Gordon Hughes wrote:
I am sorry for being a little pernickety about the implications of this
discussion, but I would like to be clear about what is or is not possible
in this respect.
The original observation was that the code:
matrix input stdvalues (3700 6200...\3800 6350...\...
gen stded = stdvalues[year-1992,filestat]
does not work. Dan found that
It was part of a larger program, and I stopped working on that approach
when I read [U]14.9.
gen int i = flpdyr-1992
gen int j = filestat
gen stded = stdvals[i,j]
does work and Section 14.9 of my User Guide (Stata 10) says that
gen stded = stdvals[2,3]
should also work.
Note that the exact wording is "where r can c are scalar expressions, to
obtain one element of matname as a scalar". Above "2" and "3" are
certainly scalar expressions, but I need to use "flpdyr" and "filestat",
for r and c which are vectors ("variables" in the language of Stata).
Furthermore, I need a vector returned. The language in 14.9 is unambiguous
(and incorrect) in claiming that that is not permitted. That is how I was
led astray, and made the incorrect claim in my initial posting.
So one inference is that -generate- can access matrix sub-elements when
either the sub-elements are either (a) constants, or (b) variables, but
not if they are defined as (c) expressions. This would be odd given the
way most of Stata works.
An alternative inference is that the problem lies in the variable type -
i.e. if variables or variable expressions are used to specify
sub-elements they must be of type int (or byte) but not float - and Dan's
second piece of code is required to force the result of the expression to
be of type int.
Can anyone tells us what is the correct inference?
The coercion to int is optional, but speeds processing if the values are
used repeatedly, as they are in my program.
Daniel Feenberg
NBER
Gordon Hughes
[email protected]
*
* 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/