Announcement

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

  • Type mismatch error when using putpdf text to display local value

    I'm using a loop to create a unique pdf report for each member in list var and need to display the N and response rate for that member in the report.
    I have defined the local value, which seems to run fine:
    foreach section of local sections {
    local clean = strtoname("`section'")
    count
    local responses = r(N)
    local response_rate = round((`responses' / `enrolled_val') * 100, 0.1)

    However when I try to display it in the report using put pdf text I get a type mismatch error, when I use the
    putpdf text("Response Count: `responses'")
    putpdf text("Response Rate: `response_rate'")

    When I try to use
    putpdf text("Response Count: `r(N)'")
    I get the same.

    How can I display the numeric value of r(N)?
    Thank you!

  • #2
    For some reason, it appears that putpdf text expects a space between the command and the expression. Compare:

    Code:
    sysuse auto, clear
    putpdf begin
    summarize mpg
    putpdf paragraph
    putpdf text("Response Count: `r(N)'")
    putpdf text ("Response Count: `r(N)'")
    Res.:

    Code:
    . putpdf text("Response Count: `r(N)'")
    type mismatch
    r(109);
    
    . 
    . putpdf text ("Response Count: `r(N)'")
    
    .

    Comment


    • #3
      Now that Andrew has solved that problem, I think you will uncover other difficulties with your code. Perhaps you have abbreviated and simplified your presentation of the code, but taking literally what you show in #1, your loop will produce exactly the same values of responses and response rate for every section, because your definitions of the local macros -responses- and -response_rate- do not depend on -`section'- and will be calculated using the entire data set. In addition to that, your local macro -enrolled_val- is undefined and will cause a syntax error in the -local response_rate- command.

      Did you perhaps intend
      Code:
      count if var == `"`section'"' // OR SOMETHING LIKE THIS
      local responses = r(N)
      And perhaps local macro -enrolled_val- is defined somewhere before the loop, or in earlier code inside the loop which was elided from the presentation in #1?

      Comment

      Working...
      X