Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Nick Cox <njcoxstata@gmail.com> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | Re: st: Creating a loop for placing observations in a macro without vallist |
Date | Wed, 7 Aug 2013 15:38:03 +0100 |
-vallist- (SSC) is a user-written program. The help file explains its history, starting out as something I did and as of 2003 being the responsibility of Patrick Joly. Whatever the details, you are asked to explain where user-written programs you refer to come from. However, -vallist- was designed to show the _distinct_ values of a variable and will not usually report them in the order in which they are observed in the data. If values are repeated, that is an extra problem. But you can write a loop easily enough, say forval i = 1/`=_N' { local macname `macname' `=varname[`i']' } However, there are big reservations here. 1. If the variable is a string, you need to use quotation marks and be careful about spaces, etc. 2. If the variable is numeric with fractional parts, you are likely to lose information. 3. Why are you doing this any way? It sounds a very odd thing to want to do. Nick njcoxstata@gmail.com On 7 August 2013 15:16, Miles Grogger <mgrogger@gmail.com> wrote: > Hi Statalisters, > > I currently have a program that is allowing me to import an excel > file, reshape it, and then place observations in a macro by using the > command: > > local macname "`=varname[1]' `varname[2]'...etc." > > This works fine for a few observations, however I eventually want to > be able to place 544 observations in the macro. Is there a loop I > could use in order to make all of this more automatic? > > Thanks, > Miles > * > * 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/