Announcement

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

  • Issues with Scalar to putdocx

    Hi,

    I have created 4 paragraphs using putdocx and used scalars from summary results to input the values I want example below:
    Code:
    count if DEPR==1 | DEPR==0
    scalar totalpts = r(N)
    
    putdocx begin, pagesize(A4) font("Times New Roman", 11, black)
    
    putdocx paragraph, font("Times New Roman", 12, black) halign(both) 
    putdocx text ("Data was analysed for")
    putdocx text (totalpts), nformat(%8.0fc)
    putdocx text (" patients......XXXX.")
    putdocx save "test", replace
    However, for one of my variables (double format) the summary result is n=33,415 yet when I open the document created it says 2. Every other results has worked so wondering if the issue is with the variable rather than my coding, which is exactly the same as all my other lines. I'll list below in case I am missing something still:

    Code:
    putdocx begin, pagesize(A4) font("Times New Roman", 11, black)
    
    putdocx paragraph, font("Times New Roman", 12, black) halign(both) 
    tab ASA if DEPR==1 & ASA==1, matcell(ASACounts)
    scalar ASA = string(ASACounts[1,1])
    putdocx text (ASA)
    Any help is appreciated, thanks in advance!

    Rhian

  • #2
    Your description is not reproducible. You can check if the scalar is indeed what you expect with

    Code:
    putdocx begin, pagesize(A4) font("Times New Roman", 11, black)
    
    putdocx paragraph, font("Times New Roman", 12, black) halign(both)
    tab ASA if DEPR==1 & ASA==1, matcell(ASACounts)
    scalar ASA = string(ASACounts[1,1])
    di ASA
    putdocx text (ASA)
    It seems easier to me to just use the count command in this instance:

    tab ASA if DEPR==1 & ASA==1, matcell(ASACounts)
    scalar ASA = string(ASACounts[1,1])
    Code:
    count if DEPR==1 & ASA==1
    where the count is stored as r(N) and can be evaluated with `=r(N)'.

    Comment


    • #3
      Thanks so much for your suggestion Andrew. i tried this and it still didnt work but I think I have identified where the issue lies. When saving the count to the scalar its saved as 2, see below:

      Code:
      count if DEPR==1 & ASA==1
        2,487
      
      . 
      end of do-file
      
      . scalar ASA = r(N)
      
      . 
      end of do-file
      
      . di ASA
      2
      
      return list
      
      scalars:
                        r(N) =  2487
      Any ideas as to why this is?

      Thanks again, Rhian

      Comment


      • #4
        Do you also have a variable named -ASA-?

        Comment


        • #5
          Hi Leonardo, that was it! Thank you, I did indeed have a variable named ASA and completely forgot about it, changed the scalar name and problem solved!!

          Thanks so much to you and Andrew for your swift help

          Comment

          Working...
          X