Forum Replies Created

Viewing 15 posts - 46 through 60 (of 69 total)
  • Author
    Posts
  • Attaullah Shah
    Keymaster
    Post count: 69

    Christopher
    I just checked it and the dec() option works fine. Perhaps, after updating asdoc, the old macros were still in the memory, please restart Stata and check again. Or perhaps, you may like to reinstall asdoc

    The new version of asdoc can be installed from my site. Copy and paste the following line in Stata and press enter.

    net install asdoc, from(http://fintechprofessor.com) replace 

    Please note that the above line has to be copied in full. After installation of the new version, then restart Stata.

    Please do remember to cite asdoc. To cite:
    In-text citation
    Tables were created using asdoc, a Stata program written by Shah (2018).

    Bibliography
    Shah, A. (2018). ASDOC: Stata module to create high-quality tables in MS Word from Stata output. Statistical Software Components S458466, Boston College Department of Economics.

    Attaullah Shah
    Keymaster
    Post count: 69

    Thanks for reporting this. Turns out that the R2 statistic is causing this problem. R2 is the default statistic and if another R2 is entered, it causes the error. For time being, you can drop R2. I shall update asdoc to handle this error.

    sysuse auto, clear
    asdoc reg price mpg rep78 headroom i.foreign , robust replace nest ///
        drop(i.foreign ) cnames(Pooled OLS) save(Regressions1) /// 
        add(Time Dummy, YES) font(Times New Roman) fs(10) dec(4) ///
        stat(N, df_m, df_r, F) 
    
    Attaullah Shah
    Keymaster
    Post count: 69

    Since Stata treats date variables as numeric, asdoc reports the numeric variable without formating it as a Stata date. I think it can be fixed sometime in future, but at the moment, the trick is to convert the date variable first to a string and then use it with asdoc, like this

    tostring Time_period, gen(time) u force
    bys time:asdoc sum Lerner_w
    Attaullah Shah
    Keymaster
    Post count: 69

    Assalam-O-Alaikum

    Thanks for your email and kind words. Can you please send a sample of your data to reproduce the error.

    Attaullah Shah
    Keymaster
    Post count: 69

    Hello
    The error message shows that you have not loaded data in Stata. If the error is not related to data, then please type

    which asreg

    and send the output from that above code. Also, if you can please share your dataset for debugging the issue.

    Attaullah Shah
    Keymaster
    Post count: 69

    The mistake you are making is the declaration of the Age text as a macro, by enclosing it in the macro symbols. In fact, Age is just a text, it is not declared as a local macro with the loc command. The correct is given below.

    clear
    set obs 100
    gen mean_age = int(uniform() * 100)
    gen stupd = mod(_n,2)
    
    ttest mean_age, by(stupd)
    
    *Get the relevant statistics
     
    loc obs1 = `r(N_1)'
    loc obs2 = `r(N_2)'
    loc mean1 = `r(mu_1)'
    loc mean2 = `r(mu_2)'
    loc dif = `mean1' - `mean2'
    loc stde = `r(se)'
    loc pval = `r(p)'
    dis `dif'
    
    sum mean_age if stupd == 0
    loc max1 = `r(max)'
    loc min1 = `r(min)'
    
    sum mean_age if stupd == 1
    loc max2 = `r(max)'
    loc min2 = `r(min)'
    
    *Write these with asdoc using the row option
    
    
    asdoc, row(Age, `obs1', `obs2', `min1', `max1', `min2', `max2', `mean1', `mean2', `dif', `stde', `pval') replace
    Attaullah Shah
    Keymaster
    Post count: 69

    The xf is an abbreviation that I use for “excluding focal”. There might be circumstances where we want to exclude the focal observation while calculating the required statistics. asrol allows excluding focal observation with two flavors. The first one is to exclude only the current observation while the second one is to exclude all observation of the relevant variable if there are similar (duplicate) values of the rangevar elsewhere in the given window. An example will better explain the distinction between the two options. Consider the following data of 5 observations, where X is the variable of interest for which we would like to calculate arithmetic mean and year is the rangevar. Our calculations do not use any rolling window, therefore the option window is dropped.

    Example A:

    asrol X, stat(mean) xf(focal) gen(xfocal)

    Example B:

    asrol X, stat(mean) xf(year) gen(xfyear)
            
              +---------------------------------------+
              | year     X        xfocal       xfyear |
              |---------------------------------------|
              | 2001   100          350           350 |
              | 2002   200          325           325 |
              | 2003   300          300     266.66667 |
              | 2003   400          275     266.66667 |
              | 2004   500          250           250 |
              +---------------------------------------+

    Explanation :

    In Example A, we invoke the option xf() as xf(focal). asrol generates a new variable xfocal that contains the mean values of the rest of the observations in the given window, excluding the focal observation. Therefore, in the year 2001, xfocal variable has a value of 350, which is the average of the values of X in the years 2002, 2003, 2003, 2004 i.e. (200+300+400+500)/4 = 350. Similarly, the second observation of the xfocal variable is 325, which is (100+300+400+500)/4 = 325. Similar calculations are made when required statistics are estimated in a rolling window.

    Example B differs from Example A in definition of the focal observation(s). In Example B, we invoke the option xf() as xf(year), where year is an existing numeric variable. With this option, the focal observation(s) is(are) defined as the current observation and other observations where the focal observation of the rangevar has duplicates. Our data set has two duplicate values in the rangevar, i.e., year 2003. Therefore, the mean values are calculated as shown bellow:

            +-------------------------------------------------------+       
            |       obs 1: (200 + 300 + 400 + 500)/4 = 350          |
            |       obs 2: (100 + 300 + 400 + 500)/4 = 325          |                       
            |       obs 3: (100 + 200 + 500 )     /3 = 266.66667    |               
            |       obs 4: (100 + 200 + 500 )     /3 = 266.66667    |       
            |       obs 5: (100 + 200 + 300 + 400)/4 = 250          |                       
            +-------------------------------------------------------+      
    

    Example using a rolling window

    *Rolling mean with minimum number of observaton while excluding focal observation

     
     webuse grunfeld
     
        bys company: asrol invest, stat(mean) win(year 4) xf(focal) 
    Attaullah Shah
    Keymaster
    Post count: 69

    Brian
    Thanks for asking. This option is currently not available in asdoc. I welcome patrons to finance specific additions to asdoc. If you are interested, please let me know and I shall work on this. To reach out to me, please contact at attaullah.shah@imsciences.edu.pk

    Attaullah Shah
    Keymaster
    Post count: 69

    Alreena
    You can use the reset option for starting a new table. See the following example
    *Example Make a nested table of 3 regressions

    sysuse auto, clear
    *First regression
    asdoc reg price mpg rep78, nest replace
    
    *Add variable headroom and then nest with existing table
    asdoc reg price mpg rep78 headroom, nest 
    
    *Add variable weight and then nest with existing table		
    asdoc reg price mpg rep78 headroom weight, nest 
    
    *Start a new table, note option reset
    
    *First regression
    asdoc reg price mpg rep78, nest reset
    
    *Add variable headroom and then nest with existing table
    asdoc reg price mpg rep78 headroom, nest 
    asdoc reg price mpg rep78 headroom weight, nest 

    asdoc reset option to start a new table in the same file


    Add additional Statistics to nested table


    You can use the add() option to add additional text or statistics to the nested table. In the following code, I first get the mean of the dependent variable using the sum command and write it to the local mean. Then pass on this info to the nested table using the add(Mean,mean’)` option.

    *First find mean of the dependent variable

    qui sum price
    local mean = `r(mean)'
    asdoc reg price mpg rep78, nest reset add(Mean, `mean')
    
    *Second regression use turn as the dependent variable
    qui sum turn
    local mean = `r(mean)'
    asdoc reg turn mpg rep78 headroom, nest add(Mean, `mean')

    Add mean of the dependent variable to nested table of asdoc

    Attaullah Shah
    Keymaster
    Post count: 69

    Can you please provide more details on what you typed and what error message you received from Stata?

    Attaullah Shah
    Keymaster
    Post count: 69

    Juan Miranda: The question you have asked on StackOverflow is on hold, so I cannot add my answer there. The loop you are using does not use asdoc on each data set that you have. So the correct code would be:

    cd "F:\datasets"
    local i : dir "F:\datasets" files "*.dta"
    foreach file in `i' {
    use `file', clear
    asdoc reg y x1 x2 x3, append nest rep(t) title(Table 1 MCO per year) dec(3) save(reg)
    }

    Please also note that there should be no space between rep and (t | se). The same applies to other options of asdoc.
    Also note: the option rep(t) is used to report t-statistics. Instead, if you want to report standard errors, you would use rep(se). However, you cannot use both rep(t|se). Perhaps, you copied this from the help file of asdoc, where the symbol pipe is used to denote that one of these can be used.

    Attaullah Shah
    Keymaster
    Post count: 69

    Dear Jostein Nordeng
    Thanks for your query. Give me some time to explore the mentioned possibilities.

    Attaullah Shah
    Keymaster
    Post count: 69

    It seems to me your previous installation still resides somewhere on your system. To completely uninstall all instances of asdoc, please do the following.

    You should first uninstall asdoc completely using the following code, then reinstall asdoc and then restart your Stata.

    net install uninstall_asdoc, from(http://fintechprofessor.com) replace
    
    uninstall_asdoc
    
    *And then install asdoc again
    net install asdoc, from(http://fintechprofessor.com) replace
    Attaullah Shah
    Keymaster
    Post count: 69

    Imma
    Yes, asdoc works with categorical variables. See this example

    sysuse nlsw88.dta
    asdoc tab race married

    tabulate categorical variables with asdoc in Stata

    Attaullah Shah
    Keymaster
    Post count: 69

    I updated asdoc today to add support for reporting p-values in the nested regression tables. You can now use the option rep(p) to report p-values. rep() option can also be used to report either :

    1. t-values using                 rep(t)
    2. standard errors using   rep(se)
    3. p-values with using         rep(p)

    The new version of asdoc can be installed from my site. Copy and paste the following line in Stata and press enter.
    net install asdoc, from(http://fintechprofessor.com) replace

    Please note that the above line has to be copied in full. After installation of the new version, then restart Stata.

    Following is an example of a nested table with p-values

    *Use auto dataset in our example
    sysuse auto, clear
    
    *First regression of the nested table
    asdoc reg price mpg rep78, nest rep(p) replace
    
    *Second regression, this time I am not using the option replace. 
    asdoc reg price mpg rep78 trunk , nest rep(p)
    
    *And one more regression
    asdoc reg price  rep78 trunk , nest rep(p)
    
    * Following is the output table
    

    reporting p-values in nested regression table of asdoc in Stata

    Please do remember to cite asdoc. To cite:
    In-text citation
    Tables were created using asdoc, a Stata program written by Shah (2018).

    Bibliography
    Shah, A. (2018). ASDOC: Stata module to create high-quality tables in MS Word from Stata output. Statistical Software Components S458466, Boston College Department of Economics.

Viewing 15 posts - 46 through 60 (of 69 total)