1606281649 Lists of variables: a few notes

This is a more general (editable) "note" on lists of variables.

1) Things for which lists of variables are very practical : loops.

2) Why bother?

3) Ways to create lists of variables: numerous.

3.a. Defining globals somewhere.

A classic move for all RAs (and the others ;) ) is to write a "global" dofile, where all globals are defined. It's a good move if you know your lists are not going to be changing along time (lists of provinces or states, lists of possible answers, list of outcome variables, etc...)

3.b. Massive use of the command ds:

ds all, has(label "growth")

ds ID year, not

will select all the variables that are not ID or year : you're working with yearly panel data, you have an identifier and a time variable, you want to retrieve the list of all other variables

Because the list you create can be updated! creating the list depending on a command allows more flexibility. Say you have yearly panel data, with an identifier ID and a time variable "year". Now, you want to... modify all the other variables all at once (say, you want to divide them by the inflation rate).

At the beginning, you only have data on gdp growth across 22 sectors. You may thus loop over a list of variables that you define as such :

foreach var of varlist gdp_sector_1-gdp_sector22 {

The only problem with specifying gdp_sector1-gdp_sector22 is that you have to change it by hand everytime your database change! Say now that you have data not only on gdp across 22 sectors, but also on... wages across 22 sectors (and you also want to divide them by inflation).

Is there of a way

results matching ""

    No results matching ""