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   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   RE: st: using infile dictionary
Date   Mon, 26 Jul 2010 08:18:26 +0200

<>
" -split- is user-written.  Get it from SSC."


It used to be user-written by NJC (-ssc d split-), but has been adopted for
official Stata now.


HTH
Martin

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Joseph Coveney
Sent: Montag, 26. Juli 2010 05:10
To: [email protected]
Cc: [email protected]
Subject: Re: st: using infile dictionary

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/

*
*   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