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]

Re: st: data import/varname problem


From   Scott Merryman <scott.merryman@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: data import/varname problem
Date   Tue, 10 Jul 2012 14:31:14 -0500

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.
>
> thanks,
> Jeph
*
*   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