Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: simple data input question- expanding macros


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: simple data input question- expanding macros
Date   Fri, 15 Aug 2008 10:15:21 +0100 (BST)

--- [email protected] wrote:
> I would like to input data that I have in strings manually in a .do
> file. That is, say I have a for loop going through a list of a bunch
> of strings, how can I use those strings to input data?

Maybe the following is what you want? See -help extended_fcn- and 
-help tokenize- for more details.

*----------- begin example ---------------
clear
local colors "red blue yellow"
local n : word count `colors'
set obs `n'
gen colors = ""
tokenize `colors'
forvalues i = 1/`n' {
	replace colors = "``i''" in `i'
}
*----------- end example -----------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html ) 

Hope this helps,
Maarten

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------

Send instant messages to your online friends http://uk.messenger.yahoo.com 
*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index