Announcement

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

  • Nick Cox
    replied
    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:
    
    

    Leave a comment:


  • Mira Bellenbaum
    replied
    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

    Leave a comment:


  • Nick Cox
    replied
    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.

    Leave a comment:


  • Mira Bellenbaum
    replied
    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

    Leave a comment:


  • Nick Cox
    replied
    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'
    }

    Leave a comment:


  • Mira Bellenbaum
    replied
    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

    Leave a comment:


  • Nick Cox
    replied
    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, 09:18.

    Leave a comment:


  • Mira Bellenbaum
    replied
    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!

    Leave a comment:


  • Mira Bellenbaum
    replied
    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!!

    Leave a comment:


  • Attaullah Shah
    replied
    David Eschweiler
    asreg does not support weights at the moment.

    Leave a comment:


  • David Eschweiler
    replied
    Hi Attaullah Shah,

    Many thanks for your command.
    Is it possible to assign different weights to different observations at time t? In my case depending on the market capitalization of the respective company.

    Thank you for your help

    Leave a comment:


  • Attaullah Shah
    replied
    You can make a table of summary statistics using asdoc, see this video https://www.youtube.com/watch?v=zdI65G6AhdU
    and this webpage for more details https://fintechprofessor.com/2018/01/31/asdoc/

    Leave a comment:


  • Yousry Ahmed
    replied
    Hi,

    Many thanks for your awesome command.

    1. How I can create a table that presents a time series means of the coefficient estimates from the yearly regressions using asreg.

    2. The table uses Newey-West adjustment with three lags to calculate p-values and reports them in parentheses

    3. The significance levels are for a test of the hypothesis that the time series mean is equal to zero, using the time series standard error of the mean estimate for each coefficient.

    Leave a comment:


  • Attaullah Shah
    replied
    asreg version 3.2 is now available for download from SSC (thanks to Kit Baum). This version fixes a minor bug in one of the Mata functions. Mata function ASREG4s0f1() would throw an error if option fit was used on a dataset that did not have enough observations for estimating a regression. To update,
    Code:
    ssc install asreg, replace

    Leave a comment:


  • Nick Cox
    replied
    I suspect you need to tell us more about the gaps.

    Leave a comment:

Working...
X