Bookmark and Share

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: Creating a loop for placing observations in a macro without vallist


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
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
[email protected]


On 7 August 2013 15:16, Miles Grogger <[email protected]> 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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index