Announcement

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

  • Store list

    Dear Stata users,
    I would like to create a variable that is the list of the countries that I am using. "label list country" or "tab country" does not permit to store my results (or the list of the countries). Could anyone please tell me a way to do this?
    Thank you

  • #2
    The variable already exists -- it's called country. But does

    Code:
    levelsof country
    do what you want?

    Comment


    • #3
      Thank you, Nick Cox for your answer.
      The problem is that I have cross-sectional data and each country appears more than once, and I don't want to delete any observation.
      Your suggestion creates a variable that lists the countries in one line, but I would like to have each country in one line, so for example, if I have 20 countries I want to create a variable that is a matrix 1x20.

      Comment


      • #4
        We can't have an easy discussion if variable means anything you want it to mean, and not even consistently. On Statalist there is one clear definition of variable, Stata's definition that a variable is (in other terms) a column in the dataset that has a variable name and a set of values,

        No variable is created by levelsof, at most a local macro (not a variable) and a stored result (not a variable), but you say that it's not what you want.

        You can't have any variable that has a different number of observations from that in the entire dataset.

        You can have a matrix in Stata so long as the values of your variable is numeric.

        You can have a matrix in Mata if the values are string.

        Code:
        . sysuse census, clear
        (1980 Census data by state)
        
        .  mata : uniqrows(st_sdata(., "state"))
                            1
             +-----------------+
           1 |        Alabama  |
           2 |         Alaska  |
           3 |        Arizona  |
           4 |       Arkansas  |
           5 |     California  |
           6 |       Colorado  |
           7 |    Connecticut  |
           8 |       Delaware  |
           9 |        Florida  |
          10 |        Georgia  |
          11 |         Hawaii  |
          12 |          Idaho  |
          13 |       Illinois  |
          14 |        Indiana  |
          15 |           Iowa  |
          16 |         Kansas  |
          17 |       Kentucky  |
          18 |      Louisiana  |
          19 |          Maine  |
          20 |       Maryland  |
          21 |  Massachusetts  |
          22 |       Michigan  |
          23 |      Minnesota  |
          24 |    Mississippi  |
          25 |       Missouri  |
          26 |        Montana  |
          27 |    N. Carolina  |
          28 |      N. Dakota  |
          29 |       Nebraska  |
          30 |         Nevada  |
          31 |  New Hampshire  |
          32 |     New Jersey  |
          33 |     New Mexico  |
          34 |       New York  |
          35 |           Ohio  |
          36 |       Oklahoma  |
          37 |         Oregon  |
          38 |   Pennsylvania  |
          39 |   Rhode Island  |
          40 |    S. Carolina  |
          41 |      S. Dakota  |
          42 |      Tennessee  |
          43 |          Texas  |
          44 |           Utah  |
          45 |        Vermont  |
          46 |       Virginia  |
          47 |    W. Virginia  |
          48 |     Washington  |
          49 |      Wisconsin  |
          50 |        Wyoming  |
             +-----------------+


        There are plenty of ways to get a listing, e.g.

        Code:
        egen tag = tag(country)
        list country if tag, noobs
        But I'm still broadly at a loss to know what you want. If you explained why you want it, there could be better answers.



        Last edited by Nick Cox; 25 May 2017, 06:21.

        Comment

        Working...
        X