Bookmark and Share

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: Panel Data Construction


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Panel Data Construction
Date   Wed, 19 Jun 2013 17:47:10 +0100

-date()- is for creating daily dates, but you have monthly dates. The
name -date()- itself goes back to earlier versions of Stata in which
daily dates were the _only_ kind of date for which Stata provided
special support (years hardly needed any such), but I've suggested
before that it is too easy to people to guess that -date()- is a kind
of generic date production function, even though all documentation is
to the contrary. -date()- has an undocumented synonym -daily()-, which
captures the meaning better.

That aside, the help for -dates and times- does answer your question:
given the daily dates you have now, -mofd()- converts to monthly
dates.
Nick
[email protected]


On 19 June 2013 14:05, Edward Crawley <[email protected]> wrote:
> Thank you for your help, after I added -sort _j Date- I got what I wanted.
>
> However, I have one follow up question:
>
> I will use my dataset for time-series and panel data calculations and
> I want to define Jan10 and Feb10 as monthly dates to Stata. I used the
> following code, but it didn't work;
>
> generate time = date(Date,"MY")
>
> Then, I figured out that Stata cannot understand Jan10 as a date.
> Thus, I changed Jan10 and Feb10 to 01/01/2010 and 01/02/2010 and used
> the following code;
>
> generate time = date(Date,"DMY")
> format time %td
>
> Now, it is defined as 01jan2010 and 01feb2010.
>
> My question is, since my dateset is monthly, can I transform these
> dates into 2010m1 and 2010m2, which will be understood by Stata for
> time-series and panel data calculations?
>
> On Wed, Jun 19, 2013 at 1:29 PM, Nick Cox <[email protected]> wrote:
>> Various solutions. Here is one that may help.
>>
>> input str5 Date GARP GARMV GARMB AKBP AKBMV AKBMB ISCP ISCMV ISCMB
>> "Jan10" 0.53 110 1.71 0.63 230 1.95 1.7 150 4.6
>> "Feb10" 0.47 120 1.54 0.55 205 1.71 1.63 100 4.43
>> end
>> reshape long GAR AKB ISC , i(Date) string
>> rename (GAR AKB ISC) (yGAR yAKB yISC)
>> rename _j which
>> reshape long y, i(Date which) string
>> reshape wide y , i(Date _j) j(which) string
>> renpfix y
>>
>> There is more advanced stuff in -reshape- for handling complicated
>> name patterns.
>>
>> Nick
>> [email protected]
>>
>>
>> On 19 June 2013 13:12, Edward Crawley <[email protected]> wrote:
>>> You are right, sorry about that. When I copy them directly,
>>> parentheses are automatically deleted.
>>>
>>> . describe
>>>
>>> Contains data
>>>   obs:             2
>>>  vars:            10
>>>  size:            70
>>> -------------------------------------------------------------------------------------------------------------------------
>>>               storage  display     value
>>> variable name   type   format      label      variable label
>>> -------------------------------------------------------------------------------------------------------------------------
>>> date            str5   %9s                    Date
>>> garp            float  %8.0g                  GAR(P)
>>> garmv           int    %8.0g                  GAR(MV)
>>> garmb           float  %8.0g                  GAR(MB)
>>> akbp            float  %8.0g                  AKB(P)
>>> akbmv           int    %8.0g                  AKB(MV)
>>> akbmb           float  %8.0g                  AKB(MB)
>>> iscp            float  %8.0g                  ISC(P)
>>> iscmv           int    %8.0g                  ISC(MV)
>>> iscmb           float  %8.0g                  ISC(MB)
>>> --------------------------------------------------------------------
>>>
>>>
>>> On Wed, Jun 19, 2013 at 12:16 AM, Nick Cox <[email protected]> wrote:
>>>> Variable names in Stata cannot include parentheses. You can't keep the
>>>> (). Import the "names" as variable labels in Stata, and show the
>>>> result of -describe-.
>>>>
>>>> Nick
>>>> [email protected]
>>>>
>>>> On 18 June 2013 21:49, Edward Crawley <[email protected]> wrote:
>>>>
>>>>> In Stata, Date GAR(P) GAR(MV) .... are copied as variable names to the
>>>>> data editor after I copy paste from Excel.
>>>>>
>>>>> If I do not keep them as variable names, then variable names will be
>>>>> var1 var2 ... as default and Date GAR(P) ... will be copied as values
>>>>> to the first cell.
>>>>>
>>>>> I don't know which one is easier to manipulate.
>>>>
>>>> On Tue, Jun 18, 2013 at 9:34 PM, Edward Crawley <[email protected]> wrote:
>>>>
>>>>>> I am trying to convert my dataset to panel data, but since I am new to
>>>>>> STATA I couldn't figure how to do it. My dataset is as follows;
>>>>>>
>>>>>> Date GAR(P) GAR(MV) GAR(MB) AKB(P) AKB(MV) AKB(MB) ISC(P) ISC(MV) ISC(MB)
>>>>>> Jan10 0.53 110 1.71 0.63 230 1.95 1.7 150 4.6
>>>>>> Feb10 0.47 120 1.54 0.55 205 1.71 1.63 100 4.43
>>>>>>
>>>>>>
>>>>>> GAR, AKB, ISC are the firms' names and P=price, MV=market value,
>>>>>> MB=market-to-book ratio.
>>>>>>
>>>>>>
>>>>>> At the end, I would like to have something like this;
>>>>>>
>>>>>> Firm Date P MV MB
>>>>>> GAR Jan10 0.53 110 1.71
>>>>>> GAR Feb10 0.47 120 1.54
>>>>>> AKB Jan10 0.63 230 1.95
>>>>>> AKB Feb10 0.55 205 1.71
>>>>>> ISC Jan10 1.7 150 4.6
>>>>>> ISC Feb10 1.63 100 4.43
>>>> *
>>>> *   For searches and help try:
>>>> *   http://www.stata.com/help.cgi?search
>>>> *   http://www.stata.com/support/faqs/resources/statalist-faq/
>>>> *   http://www.ats.ucla.edu/stat/stata/
>>> *
>>> *   For searches and help try:
>>> *   http://www.stata.com/help.cgi?search
>>> *   http://www.stata.com/support/faqs/resources/statalist-faq/
>>> *   http://www.ats.ucla.edu/stat/stata/
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/faqs/resources/statalist-faq/
>> *   http://www.ats.ucla.edu/stat/stata/
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index