Announcement

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

  • How to store strings with spaces using local command

    Hi

    I am trying to store a local set of values but i have strings with spaces in between. I tried to use double quotes but it didn't work.

    For example these two are different jobs, but stata takes Technology as a separate string. Let me know if there is a work around to view them as separate strings.

    local jobs "Technology officer" "Arts and Media Personnel"

    Thanks
    Veeresh

  • #2
    This works:

    Code:
    local jobs `" "Technology officer" "Arts and Media Personnel" "'
    
    foreach job of local jobs {
        display "`job'"
    }
    See http://www.stata.com/statalist/archi.../msg00285.html.
    You should:

    1. Read the FAQ carefully.

    2. "Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!"

    3. Describe your dataset. Use list to list data when you are doing so. Use input to type in your own dataset fragment that others can experiment with.

    4. Use the advanced editing options to appropriately format quotes, data, code and Stata output. The advanced options can be toggled on/off using the A button in the top right corner of the text editor.

    Comment


    • #3
      Roberto's code looks good. The other thing I was thinking was using a nonbreaking space:

      Code:
      local nbs = char(160)
      local jobs Technology`nbs'Officer Arts`nbs'and`nbs'Media`nbs'Personnel
      gettoken job1 job2: jobs
      macro list _jobs
      macro list _jobs1
      macro list _jobs2
      Roberto's code is simpler so use it if it works for whatever you want to do next.
      -------------------------------------------
      Richard Williams, Notre Dame Dept of Sociology
      Stata Version: 17.0 MP (2 processor)

      EMAIL: [email protected]
      WWW: https://www3.nd.edu/~rwilliam

      Comment


      • #4
        Code:
        clear all
        .occup=.object.new
        .occup.Declare array list
        .occup.list[1]="Technology officer"
        .occup.list[2]="Arts and Media Personnel"
        .occup.list[3]="Records Management"
        .occup.list[4]="Security Personnel"
        .occup.list[5]="Front office"
        .occup.list[6]="Back office"
        
        display `"`.occup.list[1]'"'
        display `"`.occup.list[2]'"'
        
        forval f=1/`=`.occup.list.arrnels'' {
          display `"`.occup.list[`f']'"'
        }
        once you have a few thousands elements in the list and run your program with a trace on, you'll notice the difference

        Best, Sergiy Radyakin

        Comment


        • #5
          That looks cool Sergiy but what exactly is it? I.e what is the help command to find out more? I've never seen anything like that. I can see where it would be useful.
          -------------------------------------------
          Richard Williams, Notre Dame Dept of Sociology
          Stata Version: 17.0 MP (2 processor)

          EMAIL: [email protected]
          WWW: https://www3.nd.edu/~rwilliam

          Comment


          • #6
            It looks like object-oriented programming. See class programming in [P] class.
            You should:

            1. Read the FAQ carefully.

            2. "Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!"

            3. Describe your dataset. Use list to list data when you are doing so. Use input to type in your own dataset fragment that others can experiment with.

            4. Use the advanced editing options to appropriately format quotes, data, code and Stata output. The advanced options can be toggled on/off using the A button in the top right corner of the text editor.

            Comment


            • #7
              Thanks guys!! You made my day. I have few follow up questions. I used the code written by Roberto but I was wondering if can format and export the t-test results to a word document.

              local jobs `" "Technology officer" "Arts and Media Personnel" "' foreach job of local jobs { display "`job'" ttest income if jf=="`c'", by (firms) }

              So basically I get like 10-20 t-test results in some nicely formatted tables. So i am wondering if the outreg2 will work. I know it usually works for regressions. Any thoughts?

              Have a great day folks!!

              Comment


              • #8
                Well, a t-test is the same as regression on a dichotomous indicator variable. So you could use -regress outcome i.group- instead of -ttest outcome, by(group)-, and then use outreg2 or your favorite other program for pretty output. I don't think any of those programs work with -ttest-, though.

                Comment

                Working...
                X