Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • XTSET with QUARTERLY data

    Dear All,

    Using Stata 14 on Windows 10 Computer, I have been trying to -xtset- a quarterly panel data which creates the start data different than the actual as:

    . xtset id date, quarterly
    panel variable: id (strongly balanced)
    time variable: date, 1960q2 to 1976q2
    delta: 1 quarter

    Then I tried used quarter() and dofq() but the Date has been created missing values as:

    . list in 1/10

    +---------------------------------------------------------------+
    | year id sp gdp fdi dcps date2 date3 |
    |---------------------------------------------------------------|
    1. | 1999-1 1 28.1 .71 1.0e+08 1068.8 . . |
    2. | 1999-2 1 28.9 1.09 3.3e+08 1133.42 . . |
    3. | 1999-3 1 30 1 2.9e+08 1159.88 . . |
    4. | 1999-4 1 26.9 1.08 4.4e+08 1176 . . |
    5. | 2000-1 1 27.8 .66 3.6e+08 1229.69 . . |
    |---------------------------------------------------------------|
    6. | 2000-2 1 32 .97 8.3e+08 1207.12 . . |
    7. | 2000-3 1 25.1 .89 8.1e+08 1220.71 . . |
    8. | 2000-4 1 22.9 1.32 8.0e+08 1243.76 . . |
    9. | 2001-1 1 25 .74 4.0e+08 1247.73 . . |
    10. | 2001-2 1 28.5 1.21 4.6e+08 1352.49 . . |
    +---------------------------------------------------------------+

    I read the DATETIME Stata manual but did not find hint there.

    Can someone suggest how to transfer the year to a quarterly recognized data which after xtset should give the true 1999-1 as start date?

    Regards

  • #2
    First, your post doesn't really help people who want to help you. The display of your example data is not useful: it is -list- output and it is extraordinarily time consuming to import into Stata. Run -ssc install dataex- and read -help dataex- for the simple instructions how to use it. Then post again using -dataex- to create your data example so that someone who wants to try to help you can recreate a faithful replica of what you have using a simple copy/paste operation.

    There is another problem. You show a command -xtset id date-, but that command can't possibly work with your data as you have no variable named date, and you do have two variables date2 and date3--so that Stata would be unable to decide which of these you might mean. So this command would have ended with an error message had you run it with the data you show.

    Second, I interpret what you wrote as meaning that you believe that -xtset, quarterly- somehow converts your dates from daily to quarterly. That is not the case. And, in fact, if your data have a daily date variable and you -xtset, quarterly- you will just get nonsense results from that. The conversion of a daily date to a quarterly date must precede -xtset, quarterly-, and is accomplished with the qofd() function.

    So, to get helpful answers, post an example of your data using -dataex-, and be sure that the example you post includes the variables that are relevant here. Also, if there are multiple date variables in your example, clearly explain in your post which is the one you want to convert to quarterly and use as the time variable in -xtset-.


    Comment


    • #3
      Dear Clyde, thanks for your detailed respnse and helping know few good practices here. As I was away from the forum for quite a long, so I tried to be in my old fashioned response style we used on Statalist archives.

      I created the data snipped using the DATAEX which shows:

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input long quarter byte id float(sp gdp) double fdi float dcps
      1 1 28.1  .71 1.023e+08 1068.7999
      2 1 28.9 1.09 3.348e+08 1133.4174
      3 1   30    1 2.915e+08  1159.879
      4 1 26.9 1.08 4.405e+08 1175.9983
      5 1 27.8  .66 3.642e+08  1229.689
      end
      format %tq quarter
      label values quarter quarter
      label def quarter 1 "1999-1", modify
      label def quarter 2 "1999-2", modify
      label def quarter 3 "1999-3", modify
      label def quarter 4 "1999-4", modify
      label def quarter 5 "2000-1", modify
      The code I used for xtset my data is:

      xtset id quarter, quarterly

      Where I got the start time: 1960q1 as default Stata produced. I wish to convert the quarter to something which can give me xtset exactly specifying the actual data in the same to start from real date.

      Lastly, I am sorry for the first email which was really not making since.

      Regards
      Last edited by Muhammad Anees; 04 Jan 2017, 10:20.

      Comment


      • #4
        Let me expand on the advice given by Clyde. Having reviewed your previous posts, it appears that you have not yet been given the following advice, and this places you at a disadvantage in posing your questions.

        You should review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your posts. Note especially sections 9-12 on how to best pose your question. The more you help others understand your problem, the more likely others are to be able to help you solve your problem. In particular, please read FAQ #12 and use dataex and CODE delimiters when posting to Statalist.

        I hope this advice will help Statalist help you more effectively.

        You mention reading the Stata DATETIME manual. I hope you have also seen the very detailed Chapter 24 (Working with dates and times) of the Stata User's Guide PDF. It's a very good introduction.

        Added: this advice crossed post #3 in cyberspace; thanks!
        Last edited by William Lisowski; 04 Jan 2017, 10:21.

        Comment


        • #5
          Dear William,

          Yes, I read the Dates and Times manual and I did not find anything how to specifically convert quarterly string to a quarterly numeric to be identified by Stata and hence to get the start date equal to what is actually in my sample.

          I also tried my best to reproduce the code snippet on DATAEX as you might seen it. I am sure that might have cleared my explanation a bit.

          Comment


          • #6
            Your problem is that your quarter variable is not a SIF date, as discussed in the references mentioned in post #2 and post #4. Putting labels on the numerical value doesn't make it something that Stata recognizes as a quarterly date. As help datetime tells us, a quarterly date is represented as the number of quarters since 1960q1, which is why your value of 1 is interpreted by Stata as 1960q2.
            Code:
            . generate date = quarter-1 + tq(1999,1)
            
            . format date %tq
            
            . list quarter date, clean
            
                   quarter     date  
              1.    1999-1   1999q1  
              2.    1999-2   1999q2  
              3.    1999-3   1999q3  
              4.    1999-4   1999q4  
              5.    2000-1   2000q1  
            
            
            . xtset id date
                   panel variable:  id (strongly balanced)
                    time variable:  date, 1999q1 to 2000q1
                            delta:  1 quarter
            Added: I negelected to mention that the dataex extract you provided was crucial in seeing where you had gone wrong. Thanks again for helping Statalist help you. And I subsequently added the xtset to my example to show that Stata recognizes date as quarterly based on its format.
            Last edited by William Lisowski; 04 Jan 2017, 10:39.

            Comment


            • #7
              Let me add to this discussion a pointer to a similar discussion a few days ago. See my post #5 and especially Clyde's post #6 in

              http://www.statalist.org/forums/foru...-date-variable
              Last edited by William Lisowski; 04 Jan 2017, 10:39.

              Comment


              • #8
                Good Morning William,

                Yes, the problem was exactly the same as I tried many ways to create Stata format following the conventions mentioned in manual but could not figure it out.

                The tip works and many thanks for that.

                Regards

                Comment


                • #9
                  Dear All,

                  I am new to the research process and using STATA. I am working on my dissertation. My data is quarterly over 2008 to 2016. How should I write the date/quarter so that STATA reads it as quarter. I have read the above discussion, but I have not beeen able to understand it since I am a beginner.

                  Your help is very much appreciated. Thanks.

                  Comment


                  • #10
                    Dear All. Please guide me arranging M&A data. I have multiple CARs of a single in a given year. I need to regress them with the firm level data. How should I arrange the data? Please guide

                    Comment


                    • #11
                      Mustabsar Awais : Your question is not visibly related to the topic of this thread. Please repost this in a new thread. I also recommend you read the FAQ for good advice on asking questions in ways that are likely to get a helpful and timely response before you do that. Your question as phrased is so broad and vague as to be essentially unanswerable. It also includes jargon like M&A and CAR that many on the forum will not understand: this is an interdisciplinary forum and it is best to pose questions in language that is understandable to all educated people. If certain abbreviations or jargon need to be used, they should be explained in your post.

                      Aliza Khan Your question requires clarification. Do you already have your data imported into a Stata dataset? If so, showing an example of what you have would enable others to give you specific code for creating Stata quarterly dates. Without knowing where you are starting, we can't draw a map for how to get where you want to go. If your data are in some other medium, such as Excel or a text file, I suggest you first import the data using the relevant command (-import excel- or -import delimited- or -infix- or whatever) first.

                      To show an example of Stata data you should use the -dataex- command. You can install it by running -ssc install dataex-. Then run -help dataex- to see the simple instructions for its use. Be sure to use it whenever you show Stata data on this Forum: it enables those who want to help you to create a completely faithful replica of your example data with a simple copy/paste operation.

                      Comment


                      • #12
                        Company 1" 2008 1.1169399820779635 10.563 .007557196590634696 .000520795979920551 10.700271227733328 .08430494785738975 .27663282525104427 1
                        "Company 1" 2008 1.1380942039000441 10.925 .012366812227074142 .0005985012231418069 10.874172351629023 .07734669884289339 .21824054472839965 1
                        "Company 1" 2008 1.2452727538116533 11.846 .01842957270430845 .0005744240929344983 10.868586014139726 .07654447616787735 .21077480819492456 1
                        "Company 1" 2008 1.2641086463519537 10.034 -.029385574354407806 .000554216301915145 10.192267870445532 .13146823727387463 .4685376938574708 1
                        "Company 1" 2009 .9892727263240826 12.458 -.0006927465362672747 .00034886791626831084 10.727293587367413 .031136158420774048 .3060724779627816 1
                        "Company 1" 2009 .8535260334925754 8.8 -.051403249630723735 .00045546420367444237 10.213143173540155 .08567511994516792 .45785449384185706 1
                        "Company 1" 2009 .9161083029661847 10.308 -.04469012768607905 .00039263058938451123 10.502417741543674 .049137634514274484 .3687859566307715 1
                        "Company 1" 2009 1.1817711991306998 9.669 -.044460127028934315 .00047003286917136764 9.773366577819743 .18119552809436662 .6767273465520741 1
                        "Company 1" 2010 1.1602165706197791 11.11 .030393207157878077 .00033300066129111585 10.838363686875082 .038113242064823 .26441036488630354 1
                        "Company 1" 2010 1.19252627777461 11.383 .03916207786206627 .00037580616680798226 10.832002007366066 .05385087615375502 .2872572676088705 1
                        "Company 1" 2010 1.1912696794868756 10.833 .03086785740754472 .0003780486971286868 10.835196600921062 .0623445283324709 .3135385966012416 1
                        "Company 1" 2010 1.1234668929197187 10.935 .027729070668352174 .00036664458600018827 10.769276945816626 .029846380678647005 .3029752166272799 1
                        "Company 1" 2011 1.1663034335493154 11.271 .014217046916254805 .0005312508360135567 10.93136329146499 .07586620236550819 .32499187520311995 1
                        "Company 1" 2011 1.1669502291417395 10.667 .01854916563232667 .0005184791337477936 10.97362434355966 .07110656029125247 .31324395439168023 1
                        "Company 1" 2011 1.1676450527210314 10.917 .015277328444588179 .00042522622218307306 10.893117612089657 .0663547991108457 .3035546246547066 1
                        "Company 1" 2011 1.0955187614411543 10.889 .02690836991927492 .00048478521300658275 10.978187653419857 .06577216521967903 .29871254891417987 1
                        "Company 1" 2012 1.0908446437333137 11.417 .011360288099525384 .0005157181051432299 11.100386147039705 .06871624314555475 .29806259314456035 1
                        "Company 1" 2012 1.0922414917199115 9.68 .009419914540981456 .0004935225739256651 11.089041441315073 .07140612950215647 .29421283356380007 1
                        "Company 1" 2012 1.0747698212393992 11.48 .01945798010813693 .0005431103147001802 11.023163351357999 .0705925538974149 .3073801985676083 1
                        "Company 1" 2012 1.1038659498018029 10.661 .011480614437353598 .0004853666898095466 11.05997815733382 .07520097460463088 .3064476587398872 1
                        "Company 1" 2013 1.003362150607792 11.336 .0137424293663726 .00046894763152020315 11.386539178881552 .05491186645434079 .2184837229626393 1
                        "Company 1" 2013 1.0525335170809822 11.293 .008465172315399006 .000454841491641427 11.14102624620945 .06693440428380187 .2746573649372408 1
                        "Company 1" 2013 .995343136221348 11.4 .008802816901408495 .00047486253948847824 11.267231120107805 .05948379958718243 .24694406716878625 1
                        "Company 1" 2013 1.059135039717564 11.267 .01368112690102219 .00042659786870919076 11.308027940371996 .05783623092850285 .23348120476301656 1
                        "Company 1" 2014 1.061343438724786 10.991 .012375345428331075 .0006113269906789641 11.467202762825012 .0566193706190762 .20934955094521324 1
                        "Company 1" 2014 1.0960147241607974 9.96 .0008307619273677513 .0006790040120199153 11.457144073070824 .055669368486683884 .214679805070737 1
                        "Company 1" 2014 1.0949686769351585 9.647 -.0047136250444681504 .0006649956369898325 11.440939032604795 .05754898857652577 .21800265963244753 1
                        "Company 1" 2014 1.0436964121991275 11.25 .009643961909383103 .00048293627132092585 11.463103079843998 .055181851792582455 .20522081759973732 1
                        "Company 12" 2008 1.0400002487964473 7.681 .028631389596762036 .0018845012273294983 9.777666286066342 .09887089438611062 .7255840951966333 2
                        "Company 12" 2008 1.0235204177877504 6.261 .020030182466730606 .0015862682767168955 9.720347893187517 .09553744590192126 .7750135627373479 2
                        "Company 12" 2008 .9794677061630486 6.242 .03214386859246665 .001661071057134541 9.700315284637993 .10040866325946601 .7864726700747149 2
                        "Company 12" 2008 1.0513158940923908 7.04 .029146021568055902 .0017825010294507527 9.752241073100093 .09949456759660921 .7469375560203168 2
                        "Company 12" 2009 1.2986977827111028 7.071 .05232010759919303 .0014643411702703372 9.236696614600541 .1449023358256535 1.2543903662819869 2
                        "Company 12" 2009 .9530790036607857 8.071 .03684863523573201 .0013021213727364164 9.726795945790029 .078863109414678 .9068649678062937 2
                        "Company 12" 2009 .9852998331085252 9.479 .030163599182004175 .0013450913266743224 9.493465228576055 .11133625776570398 1.0641694157709907 2
                        "Company 12" 2009 1.0584958217270195 7.09 -.0528897929879143 .0011547632775600948 9.780948827117136 .059063954449878324 .9095870474804439 2
                        "Company 12" 2010 1.1827141155546852 6.675 .10597161037689662 .0026920370766924653 9.74103153870618 .0483105790506005 .9829942003342179 2
                        "Company 12" 2010 1.024534990103212 6.6 -.0024005053695514977 .0025052880257121664 9.893997690900736 .04257366308054511 .8167932696234583 2
                        --more--

                        I have imported the dataset into STATA. By running the -dataex- command I get the above display.

                        Comment


                        • #13
                          how can I transform the time variable so that STAT will read it as quarters

                          Comment


                          • #14
                            You have only posted a part of the output that -dataex- gave you, and, unfortunately, that means it's missing some crucial information, such as the variable names and their data storage types. Please try again: be sure to copy the entire -dataex- output. Also, to make it shorter, we don't need this large an example for this question. Do I would do something like -dataex in 1/20-. That should give an adequate amount of data for this purpose (and it won't trigger a -more- at the end of the screen, and the important beginning of the -dataex- output will not have scrolled off the top of your screen.

                            Comment


                            • #15
                              I tried , writing quarters as 2008q1, 2008q2, 2008q3 and so on.for different companies. I read that this is the quarter date format in STATA. After specifying quarters like I mentioned, I converted the 'company # variable from a string variable to a numeric variable. I did this by using the following command,

                              egen companynum = group(A)

                              and then

                              . xtset companynum

                              which shows that variable is balanced.

                              Now I ran panel data regression, which showed the following result:


                              Listed 100 out of 308 observations
                              Use the count() option to list more

                              . xtreg TPP LTG SG C S EP EB, re

                              Random-effects GLS regression Number of obs = 308
                              Group variable: companynum Number of groups = 11

                              R-sq: within = 0.2676 Obs per group: min = 28
                              between = 0.4091 avg = 28.0
                              overall = 0.2577 max = 28

                              Wald chi2(6) = 105.49
                              corr(u_i, X) = 0 (assumed) Prob > chi2 = 0.0000

                              ------------------------------------------------------------------------------
                              TPP | Coef. Std. Err. z P>|z| [95% Conf. Interval]
                              -------------+----------------------------------------------------------------
                              LTG | .0004863 .0026377 0.18 0.854 -.0046835 .0056561
                              SG | .0862782 .1133745 0.76 0.447 -.1359316 .3084881
                              C | -.0338621 1.243967 -0.03 0.978 -2.471992 2.404268
                              S | -.0411984 .0141052 -2.92 0.003 -.068844 -.0135527
                              EP | 1.195162 .275238 4.34 0.000 .6557052 1.734618
                              EB | .1399685 .0185404 7.55 0.000 .1036299 .1763071
                              _cons | 1.366092 .1574833 8.67 0.000 1.05743 1.674754
                              -------------+----------------------------------------------------------------
                              sigma_u | .03618889
                              sigma_e | .11903071
                              rho | .08461303 (fraction of variance due to u_i)



                              But I am not sure if it incorporates quarters correctly? How can I be sure of this please?

                              Comment

                              Working...
                              X