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: using infile dictionary


From   Andrzej Niemierko <[email protected]>
To   Stata <[email protected]>
Subject   Re: st: using infile dictionary
Date   Mon, 26 Jul 2010 17:35:04 -0400

Joseph, this is very helpful! I learnt a few useful Stata programming
techniques just studying and executing your code line by line.
Thank you very much.
Andrzej





On 7/25/10 11:09 PM, "Joseph Coveney" <[email protected]> wrote:

> Andrzej Niemierko wrote:
> 
> Yes, it is easy to do what I want manually. The reason I wanted to
> "automate" it is that I have to repeat it for a few thousands of files.
> I guess I will try to do splitting my text files using PEARL.
> 
> ------------------------------------------------------------------------------
> --
> 
> Try the following.  -split- is user-written.  Get it from SSC.
> 
> Joseph Coveney
> 
> ======= Begin illustration.do ============
> 
> version 11.1
> 
> clear *
> set more off
> 
> *
> * Creating demonstration datasets
> *
> 
> set seed `=date("2010-07-26", "YMD")'
> 
> program define crDummies
>     version 11.1
>     syntax anything
> 
>     drop _all
>     set obs `=123 * 6'
>     generate str244 a = "Text in the first line"
>     replace a = string(floor(100 * runiform())) + ///
>       " " + string(floor(100 * runiform())) ///
>       if mod(_n, 123) != 1
>     outfile using "dummy`anything'.prn", noquote wide
> end
> 
> forvalues i = 1/10 {
>     crDummies `i'
> }
> 
> *
> * Begin here
> *
> 
> program define Pearl
>     version 11.1
>     syntax using/
> 
>     infix str244 a 1-244 using `"`using'"', clear
>     generate byte block = mod(_n, 123) == 1
>     replace block = sum(block)
>     generate long row = _n
>     bysort block (row): generate long observation = _n
>     drop row
>     reshape wide a, i(observation) j(block)
>     drop in 1 // I assume that you don't want the text
>     generate str a = a1 + " " + ///
>                      a2 + " " + ///
>                      a3 + " " + ///
>                      a4 + " " + ///
>                      a5 + " " + a6
>     keep a
>     split a, generate(a_) destring
>     drop a
>     local saving = substr("`using'", 1, ///
>       `=length("`using'") - 4')
>     save `"`saving'"'
> end
> 
> local file_list : dir "F:\" files "dummy*.prn"
> foreach file of local file_list {
> Pearl using `file'
> }
> exit
> 
> ========= End illustration.do ============
> 
> 
> *
> *   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/



The information in this e-mail is intended only for the person to whom it is
addressed. If you believe this e-mail was sent to you in error and the e-mail
contains patient information, please contact the Partners Compliance HelpLine at
http://www.partners.org/complianceline . If the e-mail was sent to you in error
but does not contain patient information, please contact the sender and properly
dispose of the e-mail.

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