Announcement

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

  • Creating a list of lists

    Hi,


    I am trying to create a list of variable names.
    Since I have a lot of variables I have created groups of small number of variables.

    My aim is to use the whole list or subgroups of it as a list of variable names in various commands.

    For example - lets say I have 100 variables, I created 10 local macros with each containing 10 variable names:

    ---
    Code:
    local list1 “var1 var2 … var10”
    local list2 “var11 var12 … var20”
    …
    local list10 “var91 var92 … var100”


    I now wish to recall all variables without listing all locals and with the option of retrieving subgroups of the list.
    for example (this code won't work obviously):

    ---
    Code:
    local listx “list1-list10”
    
    and
    
    local listy "list1-list4"



    How can I do this?

    Thanks

    Mor
    Stata/MP 15.1

  • #2
    Sometimes using all variables is just the default any way

    Code:
    summarize 
    
    list 
    
    edit
    and many other times you don't need this because * or _all gives you all variables

    If you want this for real (tell us why) then
    Code:
    unab all : *
    is one way to do it.

    Comment


    • #3
      I don't need this for all variables. I think you got me wrong.
      I want to be able to use a loop with subsets of variable names.
      What I essentially seek is for a way to create a list of lists.
      Although I have seen some of your replies to similar questions, none of them involved creating a macro of strings from locals that are themselves a string.

      just for clarification:

      I have -

      Code:
      local vargroup1 "var1 var2"
      local vargroup2 "var3 var4"
      local vargroup3 "var5 var6"
      and want a local that contains all variables or some of them without having to write this:

      Code:
      local vars "vargroup1 vargroup2 vargroup3"
      but instead something like:

      Code:
      local vars "vargroup*"
      or better yet:
      Code:
      local vars "vargroup1-vargroup3"
      which allows for more flexibility in choosing the subset of variables I need each time.

      Thanks ahead,

      Mor

      Stata/MP 15.1

      Comment


      • #4
        I now wish to recall all variables
        is what you said.

        Although I have seen some of your replies to similar questions, none of them involved creating a macro of strings from locals that are themselves a string.
        it's a bit risky to assert that none of my posts apply to your question.

        Given ten lists in local macros you can do things like this

        Code:
        forval j = 1/10 {
              foreach v of var `list`j'' {
                    ....
              }
        }
        I hope that you don't literally work with names like var1 to var100!

        Comment


        • #5
          Apologies for the poor phrasing.
          It is indeed risky but I meant to say I read before posting.

          this seems to be what I look for, but can you help me in creating a single macro which would contain the final list of variable names?

          (My variables have much worse names than var1 var2)
          Stata/MP 15.1

          Comment

          Working...
          X