Announcement

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

  • Create local variable list with *

    I have a large number of variables starting with either with urb7, urb8 or urb9. I would like to create a local list that includes all these variables, but excludes variables such as urb3.

    I tried

    Code:
    local urban urb7* urb8* urb9*
    di `urban'
    which gives out a syntax error and

    Code:
    local urban urb7* urb8* urb9*
    di "`urban'"
    which gives out "urb7* urb8* urb9*".

    I would like to be able to see the full list of variables, so I can get the list working in a loop afterwards (but that's another story).

    So, how do I get the list to contain: urb7_arbitrary_text1, urb7_arbitrary_text2, urb8_arbitrary_text1, and so on?

    Thank you very much.

    Best regards,
    Milan

  • #2
    Code:
    help unab

    Comment


    • #3
      You can do that with the unab command, see help unab.

      Code:
      unab varlist : urb7_*_text1 urb7_*_text2 urb8_*_text1
      di `"|`varlist'|"'
      I usually use compound quotes (`" and "') when displaying the content of local macros just in case the local macro itself contains quotes, and I usually display it between ||, so that I can see any leading or trailing white spaces.
      ---------------------------------
      Maarten L. Buis
      University of Konstanz
      Department of history and sociology
      box 40
      78457 Konstanz
      Germany
      http://www.maartenbuis.nl
      ---------------------------------

      Comment


      • #4
        Thank you, Nick Cox. That was what I was looking for.

        If anyone later finds this thread and has the same (admittedly, a bit simple-minded) question, the code that got it working for me is:

        Code:
        unab urban : urb7* urb8* urb9*
        di "`urban'"
        Thanks again.

        p.s. Did not see your response before posting, Maarten Buis. Now we have two solutions, I hope that's okay. Thanks also for the tips with compound quotes and |.
        Last edited by Milan Quentel; 25 Nov 2016, 03:56.

        Comment

        Working...
        X