Announcement

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

  • Help with Dyndoc

    Hello everyone, I was hoping someone could help me with an issue with dyndoc on Stata version 18.0

    1. I have a .txt file called objective1.txt which contains my stata commands enclosed with dynamic tags.

    2. One of the codes in the .txt file is to produce a table using the dtable command:

    dtable, continuous(age, statistics(mean sd)) continuous(timeia, statistics(median q1 q3)) factor(agegroup gender finaldiagnosis iaduration, statistics(fvfrequency fvpercent)) by(fm) title("Supplementary Table 1")

    3. When I run the stata command dyndoc objective1.txt, Stata stops at the above code and issues the ff error: no variables defined in option by ()

    4. When I run the same code in Stata do-file (without dyndoc tags), it works well.

    Can anyone please help me out - not sure what the error could be.

    Thanks.


  • #2
    Here is a minimum example, the text file ex1.txt contains:

    Code:
    ~~~
    <<dd_do>>
    use https://www.stata-press.com/data/r18/nhanes2l
    dtable bpsystol age weight i.race i.hlthstat, by(rural) sample(N(%))
    <</dd_do>>
    ~~~
    Code:
    dyndoc ex1.txt, replace
    produces the following ex1.html:

    HTML Code:
    <pre><code>. use https://www.stata-press.com/data/r18/nhanes2l
    (Second National Health and Nutrition Examination Survey)
    
    . dtable bpsystol age weight i.race i.hlthstat, by(rural) sample(N(%))
    
    --------------------------------------------------------------------------
                                                   Rural                      
                                  Urban            Rural            Total     
    --------------------------------------------------------------------------
    N(%)                       6,548 (63.3%)    3,803 (36.7%)  10,351 (100.0%)
    Systolic blood pressure 130.460 (23.526) 131.607 (22.980) 130.882 (23.333)
    Age (years)              46.835 (17.484)  48.862 (16.666)  47.580 (17.215)
    Weight (kg)              71.427 (15.363)  72.708 (15.314)  71.898 (15.356)
    Race                                                                      
      White                    5,419 (82.8%)    3,646 (95.9%)    9,065 (87.6%)
      Black                      968 (14.8%)       118 (3.1%)    1,086 (10.5%)
      Other                       161 (2.5%)        39 (1.0%)       200 (1.9%)
    Health status                                                             
      Excellent                1,609 (24.6%)      798 (21.0%)    2,407 (23.3%)
      Very good                1,713 (26.2%)      878 (23.1%)    2,591 (25.1%)
      Good                     1,878 (28.7%)    1,060 (27.9%)    2,938 (28.4%)
      Fair                       950 (14.5%)      720 (19.0%)    1,670 (16.2%)
      Poor                        389 (5.9%)       340 (9.0%)       729 (7.1%)
    --------------------------------------------------------------------------
    
    </code></pre>

    Comment


    • #3
      Hi Hua,

      Thanks for your response. I actually have it written as:

      ~~~~
      <<dd_do>>
      dtable, continuous(age, statistics(mean sd)) continuous(timeia, statistics(median q1 q3)) factor(agegroup gender finaldiagnosis iaduration, statistics(fvfrequency fvpercent)) by(fm) title("Supplementary Table 1")
      <</dd_do>>
      ~~~~

      When i type the dyndoc objective1.txt in the command prompt, I get the error:
      no variables defined
      in option by()
      r(111)



      Originally posted by Hua Peng (StataCorp) View Post
      Here is a minimum example, the text file ex1.txt contains:

      Code:
      ~~~
      <<dd_do>>
      use https://www.stata-press.com/data/r18/nhanes2l
      dtable bpsystol age weight i.race i.hlthstat, by(rural) sample(N(%))
      <</dd_do>>
      ~~~
      Code:
      dyndoc ex1.txt, replace
      produces the following ex1.html:

      HTML Code:
      <pre><code>. use https://www.stata-press.com/data/r18/nhanes2l
      (Second National Health and Nutrition Examination Survey)
      
      . dtable bpsystol age weight i.race i.hlthstat, by(rural) sample(N(%))
      
      --------------------------------------------------------------------------
      Rural
      Urban Rural Total
      --------------------------------------------------------------------------
      N(%) 6,548 (63.3%) 3,803 (36.7%) 10,351 (100.0%)
      Systolic blood pressure 130.460 (23.526) 131.607 (22.980) 130.882 (23.333)
      Age (years) 46.835 (17.484) 48.862 (16.666) 47.580 (17.215)
      Weight (kg) 71.427 (15.363) 72.708 (15.314) 71.898 (15.356)
      Race
      White 5,419 (82.8%) 3,646 (95.9%) 9,065 (87.6%)
      Black 968 (14.8%) 118 (3.1%) 1,086 (10.5%)
      Other 161 (2.5%) 39 (1.0%) 200 (1.9%)
      Health status
      Excellent 1,609 (24.6%) 798 (21.0%) 2,407 (23.3%)
      Very good 1,713 (26.2%) 878 (23.1%) 2,591 (25.1%)
      Good 1,878 (28.7%) 1,060 (27.9%) 2,938 (28.4%)
      Fair 950 (14.5%) 720 (19.0%) 1,670 (16.2%)
      Poor 389 (5.9%) 340 (9.0%) 729 (7.1%)
      --------------------------------------------------------------------------
      
      </code></pre>

      Comment


      • #4
        Looks like there is no data loaded at the time dtable is called. What happens if you add describe

        Code:
        ~~~~
        <<dd_do>>
        desc
        dtable, continuous(age, statistics(mean sd)) continuous(timeia, statistics(median q1 q3)) factor(agegroup gender finaldiagnosis iaduration, statistics(fvfrequency fvpercent)) by(fm) title("Supplementary Table 1")
        <</dd_do>>
        ~~~~

        Comment


        • #5
          You are absolutely right. Apparently, I had included the <<dd_ignore>> when i was reading in the dataset in a bid to hide sections of stata code that I did not want turning up on the html output file as I only wanted text and tables showing up on the final html output.


          Originally posted by Hua Peng (StataCorp) View Post
          Looks like there is no data loaded at the time dtable is called. What happens if you add describe

          Code:
          ~~~~
          <<dd_do>>
          desc
          dtable, continuous(age, statistics(mean sd)) continuous(timeia, statistics(median q1 q3)) factor(agegroup gender finaldiagnosis iaduration, statistics(fvfrequency fvpercent)) by(fm) title("Supplementary Table 1")
          <</dd_do>>
          ~~~~

          Comment


          • #6
            I see. You can use <<dd_do: quietly>>, something like:

            Code:
            <<dd_do:quietly>>
            use https://www.stata-press.com/data/r18/nhanes2l
            <</dd_do>>
            
            ~~~
            <<dd_do>>
            dtable bpsystol age weight i.race i.hlthstat, by(rural) sample(N(%))
            <</dd_do>>
            ~~~

            Comment


            • #7
              Great. Many thanks for your help.

              Originally posted by Hua Peng (StataCorp) View Post
              I see. You can use <<dd_do: quietly>>, something like:

              Code:
              <<dd_do:quietly>>
              use https://www.stata-press.com/data/r18/nhanes2l
              <</dd_do>>
              
              ~~~
              <<dd_do>>
              dtable bpsystol age weight i.race i.hlthstat, by(rural) sample(N(%))
              <</dd_do>>
              ~~~

              Comment

              Working...
              X