Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Nick Cox <n.j.cox@durham.ac.uk> |
To | "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu> |
Subject | RE: st: data import/varname problem |
Date | Wed, 11 Jul 2012 11:22:53 +0100 |
Evaluating names using = will cause long lists of names to be truncated. You could just copy local mymac `r(varlist)' or use e.g. -unab- to put unabbreviated names straight into a macro. insheet using ... unab wanted : * insheet using ... unab actual : * rename (`actual') (`wanted') Nick n.j.cox@durham.ac.uk Scott Merryman Something like this: . insheet using "C:\Users\scott.merryman\Desktop\variablenames.csv", clear (3 vars, 0 obs) . ds aaa bbb ccc . local name =r(varlist) . insheet using "C:\Users\scott.merryman\Desktop\data.csv", clear (3 vars, 2 obs) . l +--------------+ | v1 v2 v3 | |--------------| 1. | 1 2 3 | 2. | 4 5 6 | +--------------+ . ds v1 v2 v3 . local a= r(varlist) . rename (`a') (`name') . ds aaa bbb ccc . l +-----------------+ | aaa bbb ccc | |-----------------| 1. | 1 2 3 | 2. | 4 5 6 | +-----------------+ Scott On Tue, Jul 10, 2012 at 1:43 PM, Jeph Herrin <stata@spandrel.net> wrote: > I have a dataset that comes to me in two files. Both are comma separated > files: one is the header (list of variable names) and the other is the data. > My problem is to combine the two, so that I have variable names on the data. > > If the files were smaller, I would probably just open both in Excel and > insert the single row in the header file onto the top row of the data file, > save, and then -insheet- the result into Stata. However in this case the > number of columns (329) exceeds the maximum allowed by Excel. A second > option would be to use a text editor to insert the header on the top line, > but the dataset is almost 5GB, and even -vim- seems to be choking on it (it > crashes after 5 or so minutes, something I have never seen -vim- do before). > > I can -insheet- both files into Stata, so I have two Stata datasets, one > containing data and the other containing variable names. But, having done > that, I can't figure out a way to use the latter to name the variables in > the former. > > Any tricks I'm missing? This is US government issued data, so I can't ask > for a more intelligent delivery arrangement. > * * 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/