Announcement

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

  • Putdocx and returning the first observation of a string variable

    Hi there,

    I am working with putdocx and would like to return the first observation of a string value in putdocx text ().
    For example, I have a variable, facility, with string values and I would like to return the first observation, "facility a", text in a sentence like below:
    "At facility a you will need to conduct xx interviews". I have tried using scalar expressions like "scalar sdp=substr(facility,1,40)" but those seem to only work for numeric or missing values and I cannot return the result in putdocx text.

    Is there a way I could do this with the following dataset?

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str40 facility
    "facility a"
    "facility b"
    "facility c"
    end
    Thanks so much!


  • #2
    You need to hold the contents of a string in a local macro.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str40 facility
    "facility a"
    "facility b"
    "facility c"
    end
    
    local text "`=facility[1]'"
    di "`text'"
    Res.:

    Code:
    . di "`text'"
    facility a

    In the putdocx command, you will then have something like:

    Code:
    putdocx paragraph
    putdocx text ("At `text', I conducted XX interviews")
    ...
    For more on locals, see https://journals.sagepub.com/doi/10....36867X20931028.

    Comment


    • #3
      Thanks so much. This worked perfectly.

      Comment

      Working...
      X