Announcement

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

  • Create a Macro from Table?

    I am trying to create a macro and it is unclear to me how to go about it. My data is several hundred thousand observations across 77 different locations, ten of these locations are 'treated'. I want to make a list of the locations that surround these ten treated locations, but the only data I have is the distance from each observation to the treated location. I can use the tabulate command along with a couple of 'if' statements to get a list of the locations that surround the ten treatment locations, but how can I save that list to a macro for future use?

  • #2
    I'm not sure what you mean by "use the tabulate command along with a couple of 'if' statements to get a list of the locations that surround the ten treatment locations" but assuming that you mean you can issue the command:

    tab location if whatever

    and Stata responds with a table whose stubs are exactly the locations you want, then you can build a macro by:

    levelsof location if whatever, local(surrounding_locations)

    Before you use this, you should probably

    display `"`surrounding_locations'"'

    to make sure it looks the way you want it. If you want to strip out the quotes that Stata puts in there is a -clean- option for -levelsof- that will do that. And if you need a comma (or something else) delimited list there is also a -separate- option (not to be confused with the unrelated -separate- command).

    Hope this helps.

    Comment

    Working...
    X