Announcement

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

  • Cross-sectional analysis

    Dear Statalists,

    I have to perform a regression in two steps:

    Firstly, regression equation is estimated in cross-section for each industry-year combination using OLS. 𝑖 and 𝑡 index firms and years respectively.
    In a second step, starting from the results of the industry-year regressions above, a company- and year-specific AQ measure is computed as the absolute value of the residuals.

    The code that I'm using for the first step is: regress ΔWC_w OCF1_w OCF2_w OCF3_w Δsales_w PPE_w if year==20xx & ind_id == x But I get that that is 20xx not valid.
    Can you please advise me with a solution?
    Note that ind_id is the industry.

    Kind regards
    Diana Kalifekh
    [ATTACH=CONFIG]n1443033[/ATTACH]

  • #2
    I'm not 100% sure I understand what you're trying to do here. Your code with year == 20xx & industry = x makes no sense to me, and evidently not to Stata either, but in context with your opening paragraph, I take it you are trying to loop over combinations of years and industry, to do a regression in each such combination, and you need to save the residuals from those regressions for later use.

    Here's a simple way to do that:

    Code:
    capture program drop one_regression
    program define one_regression
        regress ΔWC_w OCF1_w OCF2_w OCF3_w Δsales_w PPE_w 
        predict residual, resid
        exit
    end
    
    runby one_regression, by(ind_id year)
    You will have to install -runby- to do this. It is written by Robert Picard and me, ans is available from SSC.

    This code will do all the regressions and will leave the residuals behind in a new variable called residual. If there are combinations of ind_id and year for which there are insufficient observations to do the regression, these combinations will be skipped over and will not appear in the data set after -runby- finishes. If your data set is large and this will take a long time, you can add the -status- option to the -runby- command and Stata will keep you updated on its progress as it goes along.

    Comment


    • #3

      For cross-sectional regressions and finding thier residuals, you can also use asreg. In the following example, I shall use the grunfeld data, estimate cross-sectional regression in each year, and produce the residuals.

      Code:
      ssc install asreg
      webuse grundfeld
      bys year: asreg invest mvalue kstock, fit
      sort company year
      list year _b_cons _b_mvalue _b_kstock _residuals in 1/10
           +---------------------------------------------------------+
           | year      _b_cons   _b_mvalue    _b_kstock   _residuals |
           |---------------------------------------------------------|
        1. | 1935    .35603339   .10249786   -.00199479    1.7099041 |
        2. | 1936    15.218946   .08370736   -.05364126   -10.816023 |
        3. | 1937   -3.3864706    .0765138    .21772236   -32.361654 |
        4. | 1938   -17.581903   .06801777    .26911462    29.063922 |
        5. | 1939   -21.154227   .06552194    .19866456    28.936612 |
           |---------------------------------------------------------|
        6. | 1940   -27.047068     .095399    .20229056    3.3090845 |
        7. | 1941   -16.519486   .11476375    .17746501   -39.082378 |
        8. | 1942   -17.618283   .14282513    .07102405   -19.290745 |
        9. | 1943   -22.763795   .11860951    .10541193    13.717157 |
       10. | 1944   -15.828145   .11816422    .07220719    31.294639 |
           +---------------------------------------------------------+
      In your example, you can add both the industry and year as a prefix to asreg, i.e.

      Code:
      bys industry year : asreg ​​​​​​​ΔWC_w OCF1_w OCF2_w OCF3_w Δsales_w PPE_w, fit
      Regards
      --------------------------------------------------
      Attaullah Shah, PhD.
      Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
      FinTechProfessor.com
      https://asdocx.com
      Check out my asdoc program, which sends outputs to MS Word.
      For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

      Comment


      • #4
        Dear sir. Schechter

        Thank you so much for you answer, it has been very helpful, and worked well.
        Actually the model is estimated to examine the quality of accruals. So in the first step I need to run this regression and get a table with Mean, SD, p10, Median, p90 for each variable and and adjusted R-squares. Can you help me with providing the code to be able to have such table?
        An example of the table is attached
        Click image for larger version

Name:	Table.PNG
Views:	1
Size:	59.0 KB
ID:	1443052

        Comment


        • #5
          Dear prof. Shah

          Thank you so much for you answer. The code you gave me is not working. I will keep trying maybe I'm doing something bad.

          Comment


          • #6
            Can you please post what you typed and what error message Stata generated? Perhaps you are trying my code as is without changing the variable names. My code uses the variable industry while your data has this variable with the name ind_id
            IF this is the case, then try :
            Code:
              
             bys ind_id year : asreg ΔWC_w OCF1_w OCF2_w OCF3_w Δsales_w PPE_w, fit
            Regards
            --------------------------------------------------
            Attaullah Shah, PhD.
            Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
            FinTechProfessor.com
            https://asdocx.com
            Check out my asdoc program, which sends outputs to MS Word.
            For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

            Comment


            • #7
              Re #4: the statistics you want to calculate can all be gotten from Stata's -tabstat- or -table- commands. These will calculate them for you and give you a usable layout, but not the one you show. For that, there are a number of user-written commands, but as I do not use those myself I can't really advise you which might be best for your preferred layout, nor show you syntax for it.

              Comment


              • #8
                Dear professor. Shah,

                Thank you so much for advise, really appreciate it.
                Indeed it worked after I started all over again. But I think there is something wrong I did before because for some variables I don't get values.
                Click image for larger version

Name:	Shah.PNG
Views:	1
Size:	33.4 KB
ID:	1443069

                Can you advise me? because I took another look on all of the calculations but everything was correct.
                In the second picture there's also rare results with a regression I performed.
                Click image for larger version

Name:	reg.PNG
Views:	1
Size:	18.1 KB
ID:	1443070

                Comment


                • #9
                  Dear Mr. Schechter,

                  I really appreciate your answer. It has been very helpful. Thank you.

                  Comment


                  • #10
                    Dear professor. Shah,

                    Is _b_cons in my case considered to be the dependent variable ΔWC_w?
                    Thank you so much in advance.

                    Comment


                    • #11
                      _b_cons is the constant of the regression.
                      https://www.theanalysisfactor.com/in...ression-model/
                      Regards
                      --------------------------------------------------
                      Attaullah Shah, PhD.
                      Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
                      FinTechProfessor.com
                      https://asdocx.com
                      Check out my asdoc program, which sends outputs to MS Word.
                      For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

                      Comment


                      • #12
                        The site cited in #11 (author KAREN GRACE-MARTIN) has this to say

                        If X never = 0, then the intercept has no intrinsic meaning. In scientific research, the purpose of a regression model is to understand the relationship between predictors and the response. If so, and if X never = 0, there is no interest in the intercept. It doesn’t tell you anything about the relationship between X and Y.
                        I stopped reading at such muddled discussion. The "intrinsic meaning" of the intercept doesn't depend on whether there are zeros in the data.

                        Comment

                        Working...
                        X