Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: save list of scalars or locals to file


From   <Stefan.Gawrich@hlpug.hessen.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: save list of scalars or locals to file
Date   Tue, 17 Apr 2012 09:45:51 +0200

Dan,

excellent solution. Fast and easy. Thank you very much! 

***

The four different - file write - lines for scalars/locals and double quoted/not double quoted in output file:

(scalars, not quoted in file)
file write `scs' `"`: display h`x''"' _n

(locals, not quoted in file)
file write `scs' `"`: display `"`h`x''"' '"' _n

(scalars, quoted in file)
file write `scs' `""`: display h`x''""' _n

(locals, quoted in file)
file write `scs' `""`: display `"`h`x''"' '""' _n


**********************************


Stefan,

Would writing it out to a txt file work for you?

tempname scs
file open `scs' using "C:\data\sc_data.txt", text write replace forvalues x = 1/`sc' {
   file write `scs' `" `: display h`x'' "' _n } file close `scs'

The line:
   file write `scs' `" `: display h`x'' "' _n

is a condensed version of these two lines:

   local temp : display h`x'
   file write `scs' `" `temp' "' _n

You may want to have the scalar values enclosed in double quotes inside the txt file:

   file write `scs' `""`: display h`x''""' _n

Hope this helps,
Dan Blanchette
Research Programming Services
Carolina Population Center
University of North Carolina
Dan_Blanchette@unc.edu



*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index