Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: How to Match Observations Over Different Date variables
From
Muhammad Anees <[email protected]>
To
[email protected]
Subject
Re: st: How to Match Observations Over Different Date variables
Date
Wed, 17 Aug 2011 12:50:01 +0500
Sorry for not being clear and having some illogical statements in my
do file. I hope it would be clear now
use "D:Research Output/data1.dta"
generate datenew1 = date(date1, "DMY")
format datenew1 %td
ren datenew1 date
sort date
save "D:Research Output/data1.dta", replace
use "D:Research Output/data2.dta"
generate datenew2 = date(date2, "DMY")
format datenew2 %td
ren datenew2 date
sort date
save "D:Research Output/data1.dta", replace
merge 1:1 date using D:Research Output/data1.dta"
save "D:Research Output/finaldata.dta", replace
I hope I am going in right direction this time.
On Wed, Aug 17, 2011 at 12:32 PM, Tirthankar Chakravarty
<[email protected]> wrote:
> I am not sure what your new do-file is trying to do, but there are a
> number of syntactical inconsistencies. For example, it should be
>
> save `data1'
>
> not
>
> save date1
>
> as "data1" is the name of the -tempfile- declared at the top of the do-file.
>
> It might be easier to point you in the right direction if you could
> make your aim clearer.
>
> T
> On Wed, Aug 17, 2011 at 12:25 AM, Muhammad Anees <[email protected]> wrote:
>> Thanks tirthankar!
>>
>> You suggestion does the job!. I appreciate your suggestion.
>>
>> However, looking into the suggestion, I tried a version of a do file,
>> which looks like below! I would appreciate if you correct me.
>>
>> generate datenew1 = date(date1, "DMY")
>> format mydate %td
>> ren datenew1 date
>> sort date
>> save date1
>> generate datenew2 = date(date2, "DMY")
>> format mydate %td
>> ren datenew2 date
>> sort date
>> save date2
>> merge 1:1 dates using `data1',
>>
>>
>> On Wed, Aug 17, 2011 at 11:44 AM, Tirthankar Chakravarty
>> <[email protected]> wrote:
>>> /*******************************************/
>>> clear*
>>> tempfile data1 data2
>>> input str10 date str1 comma float year float stock1
>>> Jan1,2005 40
>>> Jan2,2005 40
>>> Jan3,2005 40
>>> Jan4,2005 40
>>> Jan5,2005 40
>>> Jan8,2005 40
>>> Jan9,2005 40
>>> Jan10,2005 40
>>> Jan11,2005 40
>>> Jan12,2005 40
>>> end
>>> g datestr = date+"-"+string(year)
>>> g dates = daily(datestr, "MDY")
>>> drop date comma year datestr
>>> format dates %td
>>> save `data1', replace
>>>
>>> clear*
>>> input str10 date str1 comma float year float stock2
>>> Jan1,2005 30
>>> Jan2,2005 30
>>> Jan3,2005 30
>>> Jan4,2005 30
>>> Jan8,2005 30
>>> Jan9,2005 30
>>> Jan11,2005 30
>>> Jan12,2005 30
>>> Jan13,2005 30
>>> Jan14,2005 30
>>> end
>>> g datestr = date+"-"+string(year)
>>> g dates = daily(datestr, "MDY")
>>> drop date comma year datestr
>>> format dates %td
>>> save `data2', replace
>>>
>>> // merge
>>> merge 1:1 dates using `data1',
>>>
>>> // create the individuals dates
>>> g date1 = dates if(inlist(_merge, 3, 1))
>>> g date2 = dates if(inlist(_merge, 3, 2))
>>> format date* %td
>>>
>>> li
>>> /*******************************************/
>>>
>>> T
>>>
>>> On Tue, Aug 16, 2011 at 10:30 PM, Muhammad Anees <[email protected]> wrote:
>>>> Dear Listers!
>>>>
>>>> I have been working on stock prices of different firms from Jan 1,
>>>> 2005 to October 30, 2010. The problem I face is that every stock price
>>>> is obtained and is listed with somewhat different date variables and
>>>> all the date variables are not axactly matching. I need to analyse
>>>> stock prices after matching them over dates. I know how to format the
>>>> date variables in Stata with the Help of Nick and others after a
>>>> discussion on this list, but even working for weeks, I could not
>>>> figure out how to match the stock prices over a similar date index.
>>>>
>>>> My example of data looks like below:
>>>>
>>>> Date1 Stock1 Date 2 Stock2
>>>> Jan1,2005 40 Jan1,2005 30
>>>> Jan2,2005 40 Jan2,2005 30
>>>> Jan3,2005 40 Jan3,2005 30
>>>> Jan4,2005 40 Jan4,2005 30
>>>> Jan5,2005 40 Jan8,2005 30
>>>> Jan8,2005 40 Jan9,2005 30
>>>> Jan9,2005 40 Jan11,2005 30
>>>> Jan10,2005 40 Jan12,2005 30
>>>> Jan11,2005 40 Jan13,2005 30
>>>> Jan12,2005 40 Jan14,2005 30
>>>> and so till last date on the date1 variable.
>>>>
>>>> Now what I want is to have the data like
>>>>
>>>> Date1 Stock1 Date 2 Stock2
>>>> Jan1,2005 40 Jan1,2005 30
>>>> Jan2,2005 40 Jan2,2005 30
>>>> Jan3,2005 40 Jan3,2005 30
>>>> Jan4,2005 40 Jan4,2005 30
>>>> Jan5,2005 40 . .
>>>> jan6,2005 40 . .
>>>> . . . .
>>>> . . . .
>>>> Jan9,2005 40 Jan9,2005 30
>>>> Jan10,2005 40 . .
>>>> Jan11,2005 40 Jan112005 30
>>>> Jan12,2005 40 Jan122005 30
>>>> and so on.
>>>>
>>>> Now my new data should look like above. What I need is to have a
>>>> missing value for date2 and stock2 if it has missing stock data on a
>>>> date where date1 and stock1 has a stock data. It further implies both
>>>> the stocks should be arranges on a single data variable if stock1 is
>>>> present and stock is not, stock2 should treated is missing. It is
>>>> evident that if both stocks are missing then it would not be a real
>>>> problem is both have missing date. My real problem is that I could not
>>>> arrange the the stocks over a single date variable.
>>>> I would be thankful to your suggestion and guidance.
>>>>
>>>> Regards
>>>>
>>>> Muhammad Anees
>>>> *
>>>> * 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/
>>>>
>>>
>>>
>>>
>>> --
>>> Tirthankar Chakravarty
>>> [email protected]
>>> [email protected]
>>>
>>> *
>>> * 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/
>>>
>>
>>
>>
>> --
>>
>>
>> Regards
>>
>> Anees
>>
>> *
>> * 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/
>>
>
>
>
> --
> Tirthankar Chakravarty
> [email protected]
> [email protected]
>
> *
> * 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/
>
--
Regards
Anees
*
* 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/