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]

From |
Sergiy Radyakin <[email protected]> |

To |
"[email protected]" <[email protected]> |

Subject |
Re: st: using matrix as lookup table |

Date |
Thu, 23 Jan 2014 11:15:40 -0500 |

Anne Marie, the following doesn't make sense: if curcd=="j" because j is an arbitrary indexing variable name you and I have chosen in the program. We could have decided to use "MyIndexingVariable" instead. Of course it will not occur in your data. The only time you use j withouth `' (asymmetric single quotes of macro evaluation) is in the forval statement. Anywhere within forval{ } loop you must use j as `j'. My example should work if you run it, and it should produce non-missing values of the revtUSD. The example is built under the assumption that all variables in question are numeric. Since you are writing: if curcd=="j" and Stata executes the code, I suspect that at least some variables are strings in your case. With that several things would be different. Let us know, what are the types and "typical values" of all of the variables involved. Is curcd numeric? what values does it take? something like 1,2,3? or 30001, 30002, 30003? (you will not have matrices >11,000, so that matters). Best, Sergiy On Wed, Jan 22, 2014 at 10:42 PM, Knott, Anne Marie <[email protected]> wrote: > thanks so much for your help Sergiy. > I at least got something to run!, but none of the missing values in USfromlo were replaced by calls from the matrix > > here's what i entered: > > local jmax=colsof(xchgrates) > local imax=rowsof(xchgrates) > > forvalues i=1/`imax' { > forvalues j=1/`jmax' { > quietly replace USfromlo =xchgrates[`i', `j'] if curcd=="j" & year==`i' > } > } > > i put double quotes on j because stata told me i had a type mismatch when i had single quotes (j is a string) > > ________________________________________ > From: [email protected] [[email protected]] on behalf of Sergiy Radyakin [[email protected]] > Sent: Wednesday, January 22, 2014 6:41 PM > To: [email protected] > Subject: Re: st: using matrix as lookup table > > Dear Anne Marie, > you are using the wrong quotes for local. Check the closing quote. > Also reading rowsof() and colsof() doesn't make sense in your program, > since you never use the read values, but rather hardcoded constants. > It's a matter of taste and convention, but i is often the row index, > and j the column index. Just as x is usually the horizontal > coordinate, and y - vertical. > > Something like this works, (see below). > > Best, Sergiy Radyakin > > > matrix xchgrates=2.4, 2.9, 10.7 \ 4.1, 3.0, 12.0 > > local jmax=colsof(xchgrates) > local imax=rowsof(xchgrates) > > sysuse auto, clear > generate int year=foreign+1 > generate int curcd=rep78 > generate revt=price > generate revtUSD=. > > forvalues i=1/`imax' { > forvalues j=1/`jmax' { > quietly replace revtUSD=revt*xchgrates[`i', > `j'] if curcd==`j' & year==`i' > } > } > > On Wed, Jan 22, 2014 at 6:44 PM, Knott, Anne Marie <[email protected]> wrote: >> I'm trying to use a matrix of exchange rates as a lookup table for another database. I've created and verified the matrix, and am following the command structure in Cox 2012 to call it, but I keep getting the following error message: >> >> `j' is an invalid name. >> >> I deleted all the j references, but then got the same error message for i. I've tried alternative names, so assume the problem is with the quotes--I'm using a mac. >> >> Here's the code: >> >> >> local i=colsof(xchgrates) >> >> local j=rowsof(xchgrates) >> >> forvalues i=1/89 { >> >> forvalues j=1/26 { >> >> quietly replace revtUSD=revt*xchgrates[`j’, `i’] if curcd==`i’ & year==`j’ >> >> >> } >> >> } >> >> thanks for your help. >> >> >> Anne Marie Knott >> Professor of Strategy >> Olin Business School >> Washington University in St. Louis >> Campus Box 1133 >> One Brookings Drive >> St. Louis, MO 63130-4899 >> (314) 935-4679 >> [email protected] >> <http://apps.olin.wustl.edu/faculty/knott/>website<http://apps.olin.wustl.edu/faculty/knott/> >> >> * >> * For searches and help try: >> * http://www.stata.com/help.cgi?search >> * http://www.stata.com/support/faqs/resources/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/faqs/resources/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/faqs/resources/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/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/

**References**:**st: using matrix as lookup table***From:*"Knott, Anne Marie" <[email protected]>

**Re: st: using matrix as lookup table***From:*Sergiy Radyakin <[email protected]>

**RE: st: using matrix as lookup table***From:*"Knott, Anne Marie" <[email protected]>

- Prev by Date:
**Re: st: Unexpected end of file in mata.** - Next by Date:
**Re: st: Unexpected end of file in mata.** - Previous by thread:
**Re: st: using matrix as lookup table** - Next by thread:
**st: postestimation/prediction with -spatreg-** - Index(es):