Announcement

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

  • Error "Option not allowed" when creating coef

    Hey guys,

    my goal is to regress the natural logarithm of total industry sales and an index variable of years, with time serving as independent variable and take then, the antilog of the regression coefficient capturing the growth rate of sales.

    In order to calculate that I used the following command

    bys sic_d: gen sales = sum(sale)

    gen sales_log=log(sales)

    bys sic: asreg sales_log y1, wind(fyear 5)rec coef
    drop _R2 _adjR2 _b_y1 _b_cons _coef_cons _Nobs [... this command ist repeated accordingly for every year].


    However, it generates an error message after the the third line telling me "option coef" not allowed (it works fine if I calculate the standard error by using "se" instead of "coef").

    Do you guys have any idea how to solve that?

    Nick Cox Clyde Schechter maybe you guys have any idea since you have solved similar problems before?

  • #2
    The problem arises with asreg (SSC, as you are asked to explain: FAQ Advice #12), which I have never used. Attaullah Shah is the author, and active here.

    Before that, however, you use the function sum() with generate, but note that it gives the running or cumulative sum: it's not a one-to-one alternative for the function sum() (undocumented) or total() (documented) specifically written for egen.

    Comment


    • #3
      You can check the help file of asreg
      Code:
      ssc install asreg
      help asreg
      As you might notice, there is no option 'coef' in the asreg help file. The error message tells the same. Why were you using option coef, anyway?
      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
        Hey guys, thank you for your reply!

        Attaullah Shah I am trying to get the antilog of the regression coefficient which captures the growth rate of sales. You are right, there is no option like coef within asreg . Do you have any idea how I can calculate the coefficient within asreg then?

        Nick Cox With that formula I am trying to calculate total industry sales. I used the dummy variable sic_d which includes clusters all sic codes into the adequate industry. The new variable "sales" shall therefore add up each "sale" of the gvkey within the industry (dummy variable). Do you mean I should rather use "egen" and "total"?

        Thank you so much in advance!!

        Comment


        • #5
          Possibly you're missing what running and cumulative mean here. Consider the following silly example.


          Code:
          clear 
          set obs 6 
          gen sic = cond(_n < 4, 1, 2)
          gen sales = sic * 2 
          
          bysort sic : gen running = sum(sales)
          
          by sic : egen total = total(sales)
          
          list, sepby(sic)
          
               +-------------------------------+
               | sic   sales   running   total |
               |-------------------------------|
            1. |   1       2         2       6 |
            2. |   1       2         4       6 |
            3. |   1       2         6       6 |
               |-------------------------------|
            4. |   2       4         4      12 |
            5. |   2       4         8      12 |
            6. |   2       4        12      12 |
               +-------------------------------+
          There's a connection between the methods: you just choose the last value of the running sum or total, and indeed inside the egen code that is exactly what is happening.

          Comment


          • #6
            See the following example. I am using no window so asreg and reg are similar here. Compare the coefficients, highlighted in red color.
            Code:
             sysuse auto
            asreg price mpg
            
            . list _Nobs _R2 _adjR2 _b_mpg _b_cons in 1
            
                 +--------------------------------------------------------+
                 | _Nobs         _R2      _adjR2       _b_mpg     _b_cons |
                 |--------------------------------------------------------|
              1. |    74   .21958286   .20874373   -238.89435   11253.061 |
                 +--------------------------------------------------------+
            
            . reg price mpg
            
                  Source |       SS           df       MS      Number of obs   =        74
            -------------+----------------------------------   F(1, 72)        =     20.26
                   Model |   139449474         1   139449474   Prob > F        =    0.0000
                Residual |   495615923        72  6883554.48   R-squared       =    0.2196
            -------------+----------------------------------   Adj R-squared   =    0.2087
                   Total |   635065396        73  8699525.97   Root MSE        =    2623.7
            
            ------------------------------------------------------------------------------
                   price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
            -------------+----------------------------------------------------------------
                     mpg |  -238.8943   53.07669    -4.50   0.000    -344.7008   -133.0879
                   _cons |   11253.06   1170.813     9.61   0.000     8919.088    13587.03
            ------------------------------------------------------------------------------
            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
              Nick Cox thank you very much! Got it now, thanks for the example. I believe "total" is the right command for my purpose then

              Attaullah Shah thank you for you for your explanation. I am aware now that both ways generate the same coefficient and adjusted the code accordingly. However, another problem occurred when I run the code with asreg:


              bys sic_d: egen sales = total(sale)

              gen sales_log=log(sales)


              tab fyear, gen(y)


              bys sic: asreg sales_log y1, wind(fyear 5)
              drop _R2 _adjR2 _b_y1 _b_cons _Nobs

              bys sic: asreg sales_log y2, wind(fyear 5)
              drop _R2 _adjR2 _b_y2 _b_cons _Nobs

              [Continuing this until year 30]

              generate EM = _b_y2 if fyear==1981
              "_b_y2 not found"
              replace EM = _b_y3 if fyear==1982
              replace EM = _b_y4 if fyear==1983
              replace EM = _b_y5 if fyear==1984

              My goal is to regress the natural logarithm of total industry sales and an index variable of years, with time serving as independent variable and take then, the antilog of the regression coefficient capturing the growth rate of sales.
              However, I get the error message "_b_y2 not found". Somehow it does not pick up the values from above. Do you know what I did wrong?

              Comment


              • #8
                Your code shows that you dropped _b_y2 -- which does explain why Stata can't find it.

                Comment

                Working...
                X