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

From |
<pgscooter@hotmail.com> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: RE: simple data input question- expanding macros |

Date |
Fri, 15 Aug 2008 03:49:03 -0700 |

Martin Weiss, Good question about why I would want to make things complicated. I should have stated in my question that I was trying to give a simple example of what I really wanted to do. In my program I process a lot of data and then end up with some values stored in macros that I need to make a new dataset out of. Perhaps there is a better way, but I am still getting used to the Stata style of programming, which I would say is extremely different than in conventional languages (or maybe I just think that because I have not learned enough of Stata yet). I did not know about _rc, that seems like it will be a useful thing to remember in the future. Maarten Buis, that is exactly what I was looking for. Thank you! I was trying to think of a way of doing something like that (I was going to do --input--, then input whatever as observations just to expand the number and replace them after), but I doubt I would have been able to come up with anything as good as your "solution". tokenize definitely seems useful for this application. Thank you both for the replies! Scott 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/ > From: martin.weiss@uni-tuebingen.de > To: statalist@hsphsun2.harvard.edu > Subject: st: RE: simple data input question- expanding macros > Date: Fri, 15 Aug 2008 10:54:54 +0200 > > This raises questions on several levels. If the -local- does not do the job, > the -global- probably won`t fix that. Omit the equal sign which is > unnecessary. See the following for an example of what happens: > > ******* > local color "red" > cap di `color' > di _rc > di "`color'" > ******* > > On another level, why do you not paste the strings into the data editor? > Your approach to entering data seems unusual and horribly complicated... > > HTH > Martin > > -----Original Message----- > From: owner-statalist@hsphsun2.harvard.edu > [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of > pgscooter@hotmail.com > Sent: Friday, August 15, 2008 10:35 AM > To: statalist@hsphsun2.harvard.edu > Subject: st: simple data input question- expanding macros > > Hi, I apologize for such a simple question. I hope to eventually participate > in statalist on a much higher level. > > 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? > > Say, I have a macro called color. > and, I have an existing dataset with blue and green as observations (there > is only one variable, COL). > Why doesn't the following work: > > local color = "red" > input > `color' > end > > I tried the above code using a global variable as well, to no avail: > > global color = "red" > input > ${color} > end > > > Is there a better way to do this? How do I expand my macro before anything > else happens? > > Thank you! > > PS. is there any good forum online that might be better for beginner > questions? > _________________________________________________________________ > Get Windows Live and get whatever you need, wherever you are. Start here. > http://www.windowslive.com/default.html?ocid=TXT_TAGLM_WL_Home_082008 > * > * 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/ _________________________________________________________________ Talk to your Yahoo! Friends via Windows Live Messenger. Find out how. http://www.windowslive.com/explore/messenger?ocid=TXT_TAGLM_WL_messenger_yahoo_082008 * * 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/

**References**:**st: simple data input question- expanding macros***From:*<pgscooter@hotmail.com>

**st: RE: simple data input question- expanding macros***From:*"Martin Weiss" <martin.weiss@uni-tuebingen.de>

- Prev by Date:
**Re: st: RE: Tabulation task** - Next by Date:
**R: st: RE: test after ivprobit** - Previous by thread:
**st: RE: simple data input question- expanding macros** - Next by thread:
**RE: st: RE: simple data input question- expanding macros** - Index(es):

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