Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: insheet/replace with panel data


From   Christopher F Baum <baum@bc.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: Re: insheet/replace with panel data
Date   Wed, 18 Aug 2004 07:37:59 -0400

On Aug 18, 2004, at 2:33 AM, Michael wrote:

	I have several spreadsheets that contain panel data in a "wide" format
on a single variable: dates across the top, cross-sectional identifiers
down the left.  I have been reading them into Stata with -insheet- (as
CSV) and then using -reshape-, but find that this approach is
sub-optimal in that I often loose the dates -- they are recast as v2,
v3,  etc.  I can write code to re-create the dates, but this practice
is neither transparent nor general.  (Transposing the data hasn't
helped:  then I loose the cross-section identifiers.)

	I'm curious how other people approach this issue.  Perhaps there is a
better way to organize the data in the spreadsheet, or perhaps I should
use a different Stata command.  I've looked briefly at -infix- and
- -infile-, but they don't seem to address this particular issue.  (The
data are balanced and comma-separated.)  But then again, I may be
missing something.

	My ultimate goal (conceit?) is something sufficiently transparent (a
few lines of code?) that I can give to undergrads with limited Stata
experience and have them pull off a data import of this type without
any problems -- or intervention by me.  This seems like it should be
much simplier than I have made it so far.  Thanks in advance for any
suggestions.
I have some code that does the inverse of what you want, which might nevertheless be useful in setting something up for your problem. We have a web-based database access system that kicks out panel data on several variables, for several countries, and whatever years are specified in long-long format, and of course people do not know what to do with that. They would like it wide, either to use in Stata or to (gasp!) put it into a spreadsheet. We indicate that the following do-file will take the file that they have downloaded and widen it, labelling things appropriately and getting the time dimension properly labelled.

Kit

------
* This Stata 8.0 program will process a WDI data extract produced by the data
* access system, saved to file 'wdidata.download.php3' and loaded with 'insheet'
,
* reformatting the data as 'wide', with each variable in a separate column.
* This program does not save the resulting dataset.
* C F Baum 0110 rev 0714 for tsset
*
* Before running this program, you must use 'insheet using...' to
* read the "wdidata.download.php3" file into Stata. If you are using
* a desktop (Mac or Windows) version of Stata, this is most easily done
* by using the File->Filename... command to point to the file on your disk.
*
* Make integers from sercode and ccode
rena sercode ssercode
rena ccode cccode
encode ssercode,gen(sercode)
encode cccode, gen(ccode)
drop ssercode cccode
* Provide concordance for series; order in this list corresponds
* to 'var1', 'var2' etc.
tab sercode
* Rename the data to ensure that name length limits are observed
rename dataval var
* Reshape the data into panel format
reshape wide var,i(ccode year) j(sercode)
* Specify the i and t identifiers
iis ccode
tis year
format year %ty
tsset ccode year
summ
* end of do-file; use 'save' to save the data if you wish

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* 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   |   What's new   |   Site index