Announcement

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

  • #16
    David Eschweiler
    asreg does not support weights at the moment.
    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


    • #17
      Hey guys,

      I am currently trying to calculate the Industry Munificience and dynamism.
      I want to calculate munificience as mentioned by Keats and Hitt: "First, we regressed the natural logarithm of total industry sales and an index variable of years, with time serving as independent variable. Then, the antilog of the regression coefficient capturing the growth rate of sales was used as the measurement of industrial munificence". Dynamism shall be calculated accordingly " as the dispersion about the regression line estimated in the regressions used in arriving at the munificence variable just described, by dividing the standard error of the regression slope coefficient by the mean value of sales".

      An example of our data is:

      input str6 gvkey double fyear str16 sic double sale
      "001001" 1984 "5812" 32.007
      "001001" 1985 "5812" 53.798
      "001003" 1983 "5712" 13.793
      "001003" 1984 "5712" 13.829
      "001003" 1986 "5712" 36.308
      "001003" 1987 "5712" 37.356
      "001003" 1988 "5712" 32.808

      Furthermore, we use a dummy variable to cluster the sic codes into different industries using the following code:
      recode sic_n (0000/0999=1) (1000/1499=2) (1500/1799=3) (2000/3999=4) (4000/4999=5) ///
      (5000/5199=6) (5200/5999=7) (6000/6799=8) (7000/8999=9) (9100/9199=10) ///
      (9200/9899=11) (9900/9999=12), gen (sic_d)
      label variable sic_d "Dummy Variable Industry"


      I tried the following code to calculate munificience and dynamism:

      quietly gen double indmun=.
      quietly gen double inddyn=.

      quietly bysort sic fyear : egen double indsales=sum(sale)

      quietly bysort sic fyear : gen int indcount=_n
      local if=`"if sic=="\`industry'" & (fyear>\`startyr' & fyear<=\`curyear')"'

      forvalues industry=01/12 {
      forvalues curyear=1980/2010 {

      local startyr=`curyear'-5
      quietly summarize sale `if'

      local indmean = r(mean)

      quietly regress indsales fyear `if' & indcount==1, vce(r)

      local munif = _b[fyear] / `indmean'
      local dynam = _se[fyear] / `indmean'
      quietly replace indmun = `munif' if sic=="`industry'" & fyear==`curyear'
      quietly replace inddyn = `dynam' if sic=="`industry'" & fyear==`curyear'
      //di as text "Industry: `industry' fyear: `curyear' industry mean: " as result %8.3f `indmean' as text ", munificence: " as result %8.3f `munif' as text ", dynamism: " as result %8.3f `dynam' as text ", regression coefs: " _b[fyear] "(" _se[fyear] "), " _b[_cons] "(" _se[_cons] ")"
      }
      }


      Whenever I run the code, however, I get the error message "no observations" . Furthermore, I wanted to use asreg instead of the loop. Do you guys know how to correctly adjust my code?

      I really appreciate your help since I don't know how to continue.

      Thank you so much in advance!!

      Comment


      • #18
        Nick Cox is there any chance that you have an idea how to solve our problem? I would really, really appreciate your help!! Thank you so much in advance!

        Comment


        • #19
          This question (#17) is misplaced as nothing to do with asreg (SSC).


          The code is hard to follow given a puzzling attempt to define local macros in advance. Many Stata programmers have a strong prejudice against that, as recently discussed at https://www.statalist.org/forums/for...-single-quotes

          Another problem is that a loop over 01/12 won't do what you want here unless you insist on a leading zero when it is needed. This was explained in https://www.stata-journal.com/articl...article=pr0051

          Nothing here is tested, but it includes several simplifications and intended small improvements.

          Code:
          quietly {
              gen double indmun=.
              gen double inddyn=.
          
              * don't use -sum()- (undocumented since Stata 9)
              bysort sic fyear : egen double indsales = total(sale)
              by sic fyear : gen int indcount=_n
          
              tempname indmean
          
              forvalues industry=01/12 {
                  local i : di %02.0f `industry'
                  forvalues curyear=1980/2010 {
          
                      summarize sale if sic=="`i'" & inrange(fyear, `curyear' - 4, `curyear'), meanonly
                      scalar `indmean' = r(mean)
          
                      regress indsales fyear if sic=="`i'" & inrange(fyear, `curyear' - 4, `curyear') & indcount==1, vce(r)
          
                      replace indmun = _b[fyear] / `indmean' if sic=="`i'" & fyear==`curyear'
                      replace inddyn = _se[fyear] / `indmean' if sic=="`i'" & fyear==`curyear'
                  }
              }
          }
          Last edited by Nick Cox; 23 Dec 2020, 10:18.

          Comment


          • #20
            Nick Cox thank you so much for your reply!

            I am sorry, I was told that we could use asreg to simplify our problem, that's why I posted it here.

            I tried your code, however, I get an error message right behind the open brace (see screenshot). Do you know why this happens?

            I tried to solve it by plugging in the following after the brace, but the error message still occurs.
            if r(N) == 0 { /*handle cases without observations*/ } else { /* run normal code*/ }


            Thank you in advance!!
            Attached Files

            Comment


            • #21
              Possibly

              Code:
              summarize sale if sic=="`i'" & inrange(fyear, `curyear' - 4, `curyear'), meanonly
              
              if r(N) > 1 {
                  scalar `indmean' = r(mean)
                  regress indsales fyear if sic=="`i'" & inrange(fyear, `curyear' - 4, `curyear') & indcount==1, vce(r)
              
                  replace indmun = _b[fyear] / `indmean' if sic=="`i'" & fyear==`curyear'
                  replace inddyn = _se[fyear] / `indmean' if sic=="`i'" & fyear==`curyear'
              }

              Comment


              • #22
                Nick Cox , thank you sooooooo much for your help again! You really are a life saver I adjusted the code accordingly:

                quietly {

                gen double indmun=.
                gen double inddyn=.

                bysort sic fyear : egen double indsales = total(sale)
                by sic fyear : gen int indcount=_n

                tempname indmean

                forvalues industry=01/12 {
                local i : di %02.0f `industry'
                forvalues curyear=1980/2010 {

                summarize sale if sic=="`i'" & inrange(fyear, `curyear' - 4, `curyear'), meanonly

                if r(N) > 1 {
                scalar `indmean' = r(mean)
                regress indsales fyear if sic=="`i'" & inrange(fyear, `curyear' - 4, `curyear') & indcount==1, vce(r)

                replace indmun = _b[fyear] / `indmean' if sic=="`i'" & fyear==`curyear'
                replace inddyn = _se[fyear] / `indmean' if sic=="`i'" & fyear==`curyear'
                }
                }
                }
                }



                The code runs through now, however, it does not generate any values... The variables exist in the datasets but only with ".".
                Furthermore, the output shows only the beginning of the file whenever I run the whole code (you can see this in my screenshot). This is probably not normal, is it?
                Attached Files

                Comment


                • #23
                  Are there any values with SIC codes "01" "02" ... "11" "12" ? because that is what your code requires. The data example in #17 has 4-character SIC codes.

                  Comment


                  • #24
                    Nick Cox thanks again for your kind help!!

                    Yes there were a lot of them, BUT we transformed sic into a dummy variable (see picture). Thats why I typed in "1-12 " - it describes the clusters. I clustered the sic codes according to the sic website to actually see it regressed on the industries like "Construction" and not the sic codes - if you know what I mean. Furthermore, we want to drop the clusters sic_d 8, sic_d 10 and sic_d 12 from our dataset later on.
                    Should I rather cluster them after running the dynamism/munificience code? And if so, what would I type in instead "1-12"? Our original dataset contains sic codes from 100 to 9997 and are of the type str16.

                    Attached Files

                    Comment


                    • #25
                      Your code so far pays no attention to sic_d. It refers to sic, which evidently is quite different.


                      You need to loop over integers 1/12 and refer to the result of the recode.


                      Code:
                      quietly { 
                          gen double indmun=.
                          gen double inddyn=.
                      
                          * don't use -sum()- (undocumented since Stata 9) 
                          bysort sic_d fyear : egen double indsales = total(sale)
                          by sic_d fyear : gen int indcount=_n
                      
                          tempname indmean 
                      
                          forvalues i=1/12 {
                              forvalues curyear=1980/2010 {
                      
                                  summarize sale if sic_d==`i' & inrange(fyear, `curyear' - 4, `curyear'), meanonly 
                      
                                  if r(N) > 1 { 
                                      scalar `indmean' = r(mean)
                      
                                      regress indsales fyear if sic_d==`i' & inrange(fyear, `curyear' - 4, `curyear') & indcount==1, vce(r)
                      
                                      replace indmun = _b[fyear] / `indmean' if sic_d==`i' & fyear==`curyear'
                                      replace inddyn = _se[fyear] / `indmean' if sic_d==`i' & fyear==`curyear'
                                  }
                              }
                          }
                      }
                      Code:
                      
                      

                      Comment


                      • #26
                        Nick Cox you are right! Could have seen that myself! Thank you soooo much!!

                        SO sorry to annoy you again but the code above still doesn't run. When I do it it gives me
                        quietly {
                        insufficient observations.

                        I really don't know how to cope with this all as you might have noticed. Do you have any idea how I can solve this?

                        THANK YOU SO SO MUCH

                        Comment


                        • #27
                          Sorry, no more ideas from me.

                          To debug further, you need to comment out the quietly to see where the code fails.

                          Comment


                          • #28
                            Nick Cox too bad, thank you so much for your help, though!! I really appreciate it

                            Comment


                            • #29
                              Hi Attaullah Shah,
                              Sir, I am working on quarterly panel data with N=51 and T=40. I want to run a rolling regression with 15 quarters as window, where the first regression is run using first15 quarters, the nest from 2 to 16 quarters and so on. I run the code:

                              bys i : asreg interestrate gfc cpiinflation ex_ln outputgap, wind(time 15)
                              where i is countryid and time represents quarter

                              However, I get the following output where first five values are missing and then 15 keeps on repeating:
                              _Nobs _R2 _adjR2 _b_gfc _b_cpiinflation _b_ex_ln _b_outputgap _b_cons
                              . . . . . . . .
                              . . . . . . . .
                              . . . . . . . .
                              . . . . . . . .
                              . . . . . . . .
                              6 -1.14E-13 0 -1.16E-10 9.10E-13 9.5
                              7 0 0 2.91E-11 0 9.5
                              8 0 0 0 0 9.5
                              9 0 0 0 5.68E-14 9.5
                              10 0 0 9.10E-13 0 9.5
                              11 -3.55E-15 0 0 3.55E-15 9.5
                              12 -8.88E-16 0 -9.10E-13 3.55E-15 9.5
                              13 4.44E-16 0 -4.55E-13 0 9.5
                              14 1.39E-17 0 0 0 9.5
                              15 3.55E-15 0 0 3.55E-15 9.5
                              15 3.55E-15 0 -2.27E-13 3.55E-15 9.5
                              15 0.57158481 0.4547443 -0.5949871 0 17.013916 -0.8415596 -15.058147
                              15 0.67449925 0.58572632 0.07154758 0 19.157318 -0.8017373 -18.6109
                              15 0.75565307 0.68901299 -0.038887 0 21.698423 -0.8302239 -22.609611
                              15 0.81294023 0.76192392 -0.1736552 0 24.240944 -0.8290036 -27.00011
                              15 0.84876895 0.80752412 -0.1587135 0 25.290433 -0.9173466 -29.078082
                              15 0.87536891 0.84137862 -0.0433958 0 26.486147 -0.9977948 -31.588413
                              15 0.9058569 0.88018151 0.01865548 0 27.644144 -1.2697714 -34.196145
                              15 0.92468799 0.90414836 0.06770972 0 27.385615 -1.4162443 -34.279654
                              15 0.93796095 0.92104121 0.06605368 0 26.001546 -1.6653594 -31.422473
                              15 0.86956058 0.83398619 0.14156781 0 23.343965 -1.2346861 -26.792364
                              15 0.76071796 0.69545922 0.17696004 0 20.424027 -1.0653102 -21.314451
                              15 0.61998184 0.51634052 0.16265453 0 16.405722 -1.2292738 -12.935763
                              15 0.47588814 0.33294854 0.05461825 0 12.551712 -1.3845503 -4.1147822
                              15 0.2774562 0.0803988 -0.0420422 0 8.4163467 -1.0194785 6.2416644
                              15 0.09098482 -0.1569284 -0.1745475 0 1.1061531 -0.3376111 25.246986
                              15 0.09001539 -0.1581622 -0.1568791 0 1.7089324 -0.2492659 23.751656
                              15 0.10733139 -0.1361237 -0.3230389 0 1.1345878 -0.1792229 25.099124
                              15 0.33269165 0.15069846 -0.2819006 0 5.5779585 -0.6825067 14.222327
                              15 0.60416234 0.49620662 0.52108639 0 19.738484 -1.5661441 -22.344993
                              15 0.70282334 0.62177516 -0.0934901 0 20.879848 -1.4431357 -25.717625
                              15 0.80732218 0.75477368 -0.264455 0 26.188266 -1.587023 -41.526525
                              15 0.87953144 0.84667637 0.12671152 0 31.331196 -1.8803631 -57.017177
                              15 0.93054224 0.91159922 0.16418257 0 35.649422 -1.7035194 -70.749674
                              15 0.89404824 0.86515231 -0.1491169 0 33.063561 -1.0927707 -65.205697

                              Can you please help me with it?

                              Comment


                              • #30
                                #29 overlaps with https://www.statalist.org/forums/for...ng-regressions

                                Comment

                                Working...
                                X