Announcement

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

  • local member with blank

    For example, I want to construct a local called name with several names in it:
    Code:
    local name D. Trump M. Spence N. Pelosi
    Of course, Stata will take it as six persons whose names are "D." "Trump" and so on. One way to aviod this problem is to substitude the inner blank with _ , e.g. D._Trump, but this contradicts with traditions. I also tried an alternative method:
    Code:
    local name "D. Trump" "M. Spence" "N. Pelosi"
    It turned out that the first person, who names D. Trump, was treated by Stata as D. and Trump, but the rest members were treated correctly. Is there any solution to this problem? Thanks!
    The below is the full code and the result:
    Code:
    local name "D. Trump" "M. Spence" "N. Pelosi"
    foreach s of local name{
          disp "`s'"
    }
    
    local len: word count `name'
    disp `len'
    Click image for larger version

Name:	1583281959(1).png
Views:	1
Size:	5.2 KB
ID:	1539390

  • #2
    The immediate problem here is that you need compound double quotes too around the entire macro; otherwise outermost " " get stripped on evaluation.

    See the concurrent thread https://www.statalist.org/forums/for...-with-levelsof

    Comment


    • #3
      Thanks for your time! The problem has been completely solved with your help!

      Comment

      Working...
      X