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: Grouping firmid or not to tsset data ?


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Grouping firmid or not to tsset data ?
Date   Tue, 21 Jan 2014 14:51:25 +0000

Well, thanks, but I should have spotted earlier your slip in using
-group()- with -generate-, not -egen-.

If -permno- is numeric and integer-valued then it can be used in
-tsset-. Otherwise use the result of -egen, group()-. Also use its
-label- option.

Nick
[email protected]


On 21 January 2014 13:46, Abdalla, Ahmed <[email protected]> wrote:
> Nick
> You are brilliant !
> Thanks, I tried -egen firmid=group(permno) rather than gen firmid=group(permno)-  and it worked perfectly.
>
> I use
> egen firmid=group(permno)
> gen timeid=ym(yr,mth)
> This means that in the firmid I use the-generate- command with group, and in the timeid -I use the other function you suggested .
> By the way, there are no duplicates now either on permno yr mth (or) firmid timeid , and from a quick visual inspection, I can see that tsset firmid timeid is equivalent to tsset permno timeid now. I believe there is no preference now if I use the firmid or permno besides timeid in -tsset-ing my panel or sorting my data. Do you agree ?
>
> Thanks
>
> The last code now for reference is:
> ****Begin code****
> use ccm2.dta,clear
> compress
> format datadate %d
> gen yr=year(datadate)
> gen mth=month(datadate)
> rename lpermno permno
> drop if permno==.
>
> sort permno yr mth
> duplicates drop permno yr,force //to delete firms that changed their fiscal year reporting
> save ccm_2.dta,replace
>
> use crsp2.dta,clear
> compress
> format date %d
> gen yr=year(date)
> gen mth=month(date)
> drop if permno==.
> sort permno yr mth
> duplicates drop permno yr mth,force
> save crsp_2,replace
>
> merge 1:1 permno yr mth using ccm_2.dta
> compress
> egen firmid= group(permno)
> gen timeid = ym(yr, mth)
> duplicates report firmid timeid
> tsset firmid timeid
> gen prc3=f3.prc
> keep if _merge==3
> save ccm2_crsp2.dta,replace
> ***End code***
>
> ________________________________________
> From: [email protected] <[email protected]> on behalf of Nick Cox <[email protected]>
> Sent: 20 January 2014 21:20
> To: [email protected]
> Subject: Re: st: Grouping firmid or not to tsset data ?
>
> In other words,
>
> -group()- is used with -generate- is emphatically _NOT_ the -group()-
> as used with -egen-.
>
>
> Nick
> [email protected]
>
>
> On 20 January 2014 21:16, Nick Cox <[email protected]> wrote:
>> If you really are typing
>>
>> gen firmid = group(permid)
>>
>> then that triggers the undocumented Stata function -group()-. That's
>> going to be very wrong for you. With
>>
>> egen firmid = group(permid)
>>
>> you might try
>>
>> egen double firmid = group(permid)
>>
>> instead.
>>
>> Nick
>> [email protected]
>>
>>
>> On 20 January 2014 19:03, Abdalla, Ahmed <[email protected]> wrote:
>>> Dear Statalist
>>> I have a panel id (permno) and two time variables (yr) and (mth) and want to tsset my panel based on permno yr mth
>>> I run:
>>> gen timeid = ym(yr, mth)
>>> gen firmid=group(permno)
>>>
>>> tsset firmid timeid
>>> //I get the error message -repeated time values within panel
>>>
>>> when I run tsset permno timeid
>>> //it works properly.
>>>
>>> I changed my data set, and used another data set to rule out any problems with my data, however still get the same results !
>>>
>>> Can I tsset when only the time variables are grouped in one timeid and the firmid is not grouped ? Is it correct?

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