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

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


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: reshape long does not recognize negative date values
Date   Wed, 15 Sep 2004 10:38:41 +0100

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 
[email protected] 

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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index