Note that there are some explanatory texts on larger screens.

plurals
  1. POStata: Appending multiple files and extracting variables from file names
    primarykey
    data
    text
    <p>I have 114 files with .dat extension to convert to Stata/SE and append, with substantial number of variables (varying from 81 to 16800). I have reset max number of variables to 32000 (<code>set maxvar 32000</code>), increased the memory (<code>set mem 500m</code>) and I was using the following algorithm to combine large number of files and to generate several variables by extracting parts of file names: <a href="http://www.ats.ucla.edu/stat/stata/faq/append_many_files.htm" rel="nofollow">http://www.ats.ucla.edu/stat/stata/faq/append_many_files.htm</a></p> <p>The code looks as follows:</p> <pre><code>cd "C:\Users\..." ! dir *.dat /a-d /b &gt;d:\Stata_directory\Products_batchfilelist.txt file open myfile using "d:\Stata_directory\Products_batchfilelist.txt", read file read myfile line drop _all insheet using `line', comma names gen n = substr("`line'",10,1) gen m = substr("`line'",12,1) gen playersnum = substr("`line'",14,1) save Products_merged.dta, replace drop _all file read myfile line while r(eof)==0 { insheet using `line', comma names gen n = substr("`line'",10,1) gen m = substr("`line'",12,1) generate playersnum = substr("`line'",14,1) save `line'.dta, replace append using Products_merged.dta save Products_merged.dta,replace drop _all file read myfile line } </code></pre> <p>The problem is that although variables <code>n,m,playersnum</code>extracted from file names are present in each individual file, they disappear in the final "Products_merged.dta" file. Could anyone tell me what could be the problem and if it is possible to solve with Stata/SE?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload