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

Re: st: RE: reshape long does not recognize negative date values


From   "M. Douglas Berg" <eco_mdb@shsu.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: reshape long does not recognize negative date values
Date   Wed, 15 Sep 2004 09:59:03 -0500

Thank you!
I implemented your suggestions and they worked like a charm. I appreciate your help.

I also wish to thank Jean Ries for replying.

Doug Berg


Nick Cox wrote:


You are putting the blame in the wrong place, I think.
-insheet- tries hard to convert your "labels", meaning not Stata labels, but column headers in your file, into variable names, but "-" is not legal within variable names and if it is stripped the problem then will be that "p-1" and "p1" cannot be distinguished. So it seems
that your variable names will get messed up well before -reshape- ever sees them. The problem therefore is the implicit assumption that -insheet- will break Stata's rules to satisfy your preferences.
One work-around is this:
Your .csv file, it seems, has a first line something like this:
permid,p-2,p-1,p0,p1,p2
Change the "permid" to "id".
Change all the "-" signs to underscores "_". "_" is allowed within variable names. You should be able to do this easily in any text editor.
Now -insheet- as before.
. reshape long p, i(id) j(qtime) string
The change of name of -permid- to -id- stops -permid- getting bundled in with variables whose names start with -p-. The -string- option flags that the underscores are OK, but time will be a string variable.
Now the underscores must be mapped back again:
replace qtime = subinstr(qtime,"_","-",1) destring qtime, replace
and you should be nearer where you want to be.
Nick n.j.cox@durham.ac.uk
M. Douglas Berg



I have a comma seperated (csv) file with quarterly data on variable p. The column headings are of the form p0, p1, etc for 1960q1, 1960q2. For periods prior to 1960 I labelled the columns p-1, p-2, etc for 1959q4, 1959q3.
I use the command :

insheet using qp.csv

to input the data into Stata.

Then I do the following:
reshape long p, i(permno) j(qtime)
format qtime %tq

Stata then creates variable v1, v2, v3, .... for all of the dates prior to 1960q1.

How should I specify the dates in the csv file so that Stata picks them up correctly?

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



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