Announcement

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

  • Using ASDOC with loop

    Dear collegues,

    I want to create mean of variables in a loop and I use the following command

    foreach var of varlist x1 x2 x3 {
    asdoc table `var', c(mean y1)
    }



    I get result for x1 but ASDOC is not working and I get error message:

    astable(): 3301 subscript invalid
    <istmt>: - function returned error



    Any idea how I can make 'asdoc' to work?

  • #2
    If you just want to create means of the given variables, then you need something like this
    Code:
     asdoc sum x1 x2 x3 y1, stat(mean) replace
    Still if you want your code in #1 to work, please first update asdoc and try it again.
    Code:
     ssc install asdoc, replace
    If it fails on your data set, then please post your data using dataex (from SSC).
    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


    • #3
      Dear all,
      I have the same problem using the table command. However, updating does not work.
      I'm using Stata 15 (updated).

      Code:
      sysuse auto, clear
      asdoc table rep78 foreign, c(mean mpg) format(%9.2f) center replace
      HTML Code:
      note: cellwidth too small, cannot display column heading;
      to increase cellwidth, specify cellwidth(#)
      
      --------------------------
      Repair    |
      Record    |    Car type  
      1978      | Domes    Forei
      ----------+---------------
              1 | 21.000        
              2 | 19.125        
              3 | 19.000    23.333
              4 | 18.444    24.889
              5 | 32.000    26.333
      --------------------------
                     astable():  3301  subscript invalid
                       <istmt>:     -  function returned error
      Any ideas to make asdoc work with the table command?

      Comment


      • #4
        I am using asdoc Version 2.2 ; Oct 23, 2018. You can confirm your version by typing
        Code:
        which asdoc
        Even if you have version 2.2, it is possible that the update was not successful. so update it again by
        Code:
        ssc install asdoc, replace
        Please also mention whether you are using Windows, MacOS or other operating systems.
        I tried your example, and it produced the following table.
        Code:
        sysuse auto, clear
        asdoc table rep78 foreign, c(mean mpg) format(%9.2f) center replace
        Click image for larger version

Name:	table asdoc.png
Views:	1
Size:	11.4 KB
ID:	1471261


        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


        • #5
          Thank you for the quick reply!
          Stata reports that asdoc is of Version 2.2 Oct 23, 2018. I again updated it.

          My operating system is macOS High Sierra.

          I still cannot replicate the table as I get the same error message.

          Any other ideas?

          Comment


          • #6
            asdoc was written on a Windows machine. It is possible macOS and Windows have different conventions for carriage returns and therefore asdoc encounters this error. I am planning to get macOS and troubleshoot all such issues. Thanks for reporting it.
            Last edited by Attaullah Shah; 20 Nov 2018, 10:06.
            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
              Thanks for the clarification. Looking forward to the updated version.
              Best regards,

              Comment


              • #8
                Dear All I am also trying to use asdoc in looping but it gives me the following error.

                asdoctable(): 3301 subscript invalid
                <istmt>: - function returned error
                r(3301);

                Any one who can help me .
                Thank you

                Comment


                • #9
                  Fissha Asmare
                  Please provide the following info:

                  1. A sample of your dataset using dataexprogram that can be downloaded from SSC
                  2. The Stata codes that you are using with asdoc
                  3. The asdoc version, i.e. type
                  Code:
                  which asdoc
                  4. Infor on the operating system and your version of Stata
                  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


                  • #10
                    Thank you for your timely response. Kindly find the informations below.
                    1. input float(Consumption_percentage Store_may30_percentage)
                    100 0
                    . 0
                    75 25
                    100 0
                    60 1
                    60 1
                    . 0
                    . 0
                    . 0
                    80 0
                    . 0
                    . 0
                    80 .5
                    90 .5
                    . 0
                    93.33334 .3333333
                    100 0
                    97.5 .5
                    66.666664 53.33333
                    70 60
                    86.66666 53.33333
                    . 0
                    100 0
                    100 1
                    . 0
                    90 0
                    100 .5
                    83.33334 0
                    70 0
                    75 25
                    60 0
                    75 15
                    62.5 25
                    . 0
                    75 50
                    80 50
                    70 40
                    80 33.333332
                    0 0
                    25 0
                    16.666666 0
                    83.33334 25
                    100 0
                    42.85714 0
                    100 0
                    60 0
                    100 0
                    66.666664 66.666664
                    70 0
                    90 0
                    80 11.428572
                    80 40
                    100 90
                    20 60
                    50 50
                    100 33.333332
                    100 50
                    85.71429 14.285714
                    93.75 37.5
                    100 66.666664
                    100 50
                    66.666664 66.666664
                    100 75
                    100 50
                    50 83.33334
                    100 100
                    50 0
                    50 0
                    100 0
                    100 50
                    100 66.666664
                    100 50
                    75 62.5
                    50 75
                    29.62963 29.62963
                    100 53.33333
                    100 50
                    100 42.85714
                    100 0
                    62.5 37.5
                    100 0
                    50 25
                    75 50
                    100 33.333332
                    83.33334 83.33334
                    100 66.666664
                    80 80
                    100 75
                    20 0
                    100 50
                    100 75
                    100 95
                    50 81.25
                    50 93.75
                    0 0
                    100 0
                    100 25
                    20 0
                    100 62.5
                    100 50
                    end

                    2. foreach x of varlist Store_may30_percentage Sold_percentage{
                    asdoc ttest `x' if crop_type_1 ==1&agpstatus ==1 , by(year) stat(obs mean df t p)
                    asdoc ttest `x' if crop_type_1 ==1&agpstatus ==2 , by(year) rowappend
                    asdoc ttest `x' if crop_type_1 ==3&agpstatus ==1 , by(year) rowappend
                    asdoc ttest `x' if crop_type_1 ==3&agpstatus ==2 , by(year) rowappend
                    asdoc ttest `x' if crop_type_1 ==4&agpstatus ==1 , by(year) rowappend
                    asdoc ttest `x' if crop_type_1 ==4&agpstatus ==2 , by(year) rowappend
                    asdoc ttest `x' if crop_type_1 ==5&agpstatus ==1 , by(year) rowappend
                    asdoc ttest `x' if crop_type_1 ==5&agpstatus ==2 , by(year) rowappend
                    asdoc ttest `x' if crop_type_1 ==6&agpstatus ==1 , by(year) rowappend
                    asdoc ttest `x' if crop_type_1 ==6&agpstatus ==2 , by(year) rowappend
                    asdoc ttest `x' if crop_type_1 ==9&agpstatus ==1 , by(year) rowappend
                    asdoc ttest `x' if crop_type_1 ==9&agpstatus ==2 , by(year) rowappend
                    asdoc ttest `x' if crop_type_1 ==12&agpstatus ==1 , by(year) rowappend
                    asdoc ttest `x' if crop_type_1 ==12&agpstatus ==2 , by(year) rowappend
                    asdoc ttest `x' if crop_type_1 ==16&agpstatus ==1 , by(year) rowappend
                    asdoc ttest `x' if crop_type_1 ==16&agpstatus ==2 , by(year) rowappend
                    asdoc ttest `x' if crop_type_1 ==19&agpstatus ==1 , by(year) rowappend
                    asdoc ttest `x' if crop_type_1 ==19&agpstatus ==2 , by(year) rowappend
                    asdoc ttest `x' if crop_type_1 ==26&agpstatus ==1 , by(year) rowappend
                    asdoc ttest `x' if crop_type_1 ==26&agpstatus ==2 , by(year) rowappend
                    asdoc ttest `x' if crop_type_1 ==31&agpstatus ==1 , by(year) rowappend
                    asdoc ttest `x' if crop_type_1 ==31&agpstatus ==2 , by(year) rowappend
                    asdoc ttest `x' if crop_type_1 ==37&agpstatus ==1 , by(year) rowappend
                    asdoc ttest `x' if crop_type_1 ==37&agpstatus ==2 , by(year) rowappend
                    asdoc ttest `x' if crop_type_1 ==46&agpstatus ==1 , by(year) rowappend
                    asdoc ttest `x' if crop_type_1 ==46&agpstatus ==2 , by(year) rowappend
                    }
                    3. !Version 2.3.3.3:
                    4. Windows with stata 14

                    Comment


                    • #11

                      The data you have posted does not have the following variables which appear in your code.
                      crop_type_1
                      year
                      agpstatus

                      Second, there are merged values in your code, is it a coding mistake or pasting issue. So why not try a single line and if that works, the loop should work too.

                      Code:
                      asdoc ttest Store_may30_percentage if crop_type_1 == 1 & agpstatus == 1 , by(year) stat(obs mean df t p)
                      asdoc ttest Sold_percentage if crop_type_1 == 1 & agpstatus == 1 , by(year) stat(obs mean df t p) rowappend
                      Do these lines work? if Not, then please reinstall asdoc with

                      Code:
                      ssc install asdoc, replace
                      Last edited by Attaullah Shah; 17 Apr 2019, 11:49.
                      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
                        This is the command that I am running. But it only work for the first two lines.

                        local utilization Store_may30_percentage Sold_percentage Consumption_percentage
                        foreach var in `utilization'{
                        asdoc ttest `var' if crop_type_1 ==1 & agpstatus ==1, by(year) stat(obs mean df t p)
                        asdoc ttest `var' if crop_type_1 ==1 & agpstatus ==2, by(year) rowappend
                        asdoc ttest `var' if crop_type_1 ==3 & agpstatus ==1 , by(year) rowappend
                        asdoc ttest `var' if crop_type_1 ==3 & agpstatus ==2 , by(year) rowappend
                        asdoc ttest `var' if crop_type_1 ==4 & agpstatus ==1 , by(year) rowappend
                        asdoc ttest `var' if crop_type_1 ==4 & agpstatus ==2 , by(year) rowappend
                        asdoc ttest `var' if crop_type_1 ==5 & agpstatus ==1 , by(year) rowappend
                        asdoc ttest `var' if crop_type_1 ==5 & agpstatus ==2 , by(year) rowappend
                        asdoc ttest `var' if crop_type_1 ==6 & agpstatus ==1 , by(year) rowappend
                        asdoc ttest `var' if crop_type_1 ==6 & agpstatus ==2 , by(year) rowappend
                        asdoc ttest `var' if crop_type_1 ==9 & agpstatus ==1 , by(year) rowappend
                        asdoc ttest `var' if crop_type_1 ==9 & agpstatus ==2 , by(year) rowappend
                        asdoc ttest `var' if crop_type_1 ==12 & agpstatus ==1 , by(year) rowappend
                        asdoc ttest `var' if crop_type_1 ==12 & agpstatus ==2 , by(year) rowappend
                        asdoc ttest `var' if crop_type_1 ==16 & agpstatus ==1 , by(year) rowappend
                        asdoc ttest `var' if crop_type_1 ==16 & agpstatus ==2 , by(year) rowappend
                        asdoc ttest `var' if crop_type_1 ==19 & agpstatus ==1 , by(year) rowappend
                        asdoc ttest `var' if crop_type_1 ==19 & agpstatus ==2 , by(year) rowappend
                        asdoc ttest `var' if crop_type_1 ==26 & agpstatus ==1 , by(year) rowappend
                        asdoc ttest `var' if crop_type_1 ==26 & agpstatus ==2 , by(year) rowappend
                        asdoc ttest `var' if crop_type_1 ==31 & agpstatus ==1 , by(year) rowappend
                        asdoc ttest `var' if crop_type_1 ==31 & agpstatus ==2 , by(year) rowappend
                        asdoc ttest `var' if crop_type_1 ==37 & agpstatus ==1 , by(year) rowappend
                        asdoc ttest `var' if crop_type_1 ==37 & agpstatus ==2 , by(year) rowappend
                        asdoc ttest `var' if crop_type_1 ==46 & agpstatus ==1 , by(year) rowappend
                        asdoc ttest `var' if crop_type_1 ==46 & agpstatus ==2 , by(year) rowappend
                        }

                        Comment


                        • #13
                          You have not answered my question, neither you have provided the required dataset. The following sentence does not tell anything about what does not work for you.
                          But it only work for the first two lines.
                          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


                          • #14
                            Hi there, Thank you for your excellent program!

                            However, I do have a query. Has there been any difficulty in finding paths with the new version? It works perfectly on my local machine, but when I am using a dataset on a machine at a secure location, a program which previously worked with the old version keeps falling over with error messages such as "<istmt>: 3499 asdoc_tab_onevar() not found". The ado files are kept quite separate from the data in the secure location, but i thought I had successfully pointed at the correct ado directory.

                            Comment


                            • #15
                              Davd NF Bell
                              Thanks for your feedback and kind words. I have not changed anything related to paths or directories in the new version. The problem you are referring to is related to the installation folder. I have not worked with remote servers installation, but you should ask the system administrator to install asdoc for you on the remote server. If that is not possible, then you can place the lasdoc.mlib file in the current Stata directory, if that is local and you can copy the file there.
                              http://fintechprofessor.com/lasdoc.mlib
                              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

                              Working...
                              X