# Observation markers

It can be helpful with panel data to have the observations identified by mnemonic markers. A special function available in the `genr` command is designed to facilitate this.

Suppose that in a panel consisting of states observed over several periods, the states are identified by two-letter codes in the left-most column of the original datafile. When the stacking operation is performed, these codes will be stacked along with the data values. If the first row is marked `AR` for Arkansas, then the marker `AR` will be shown on each row containing an observation for Arkansas. That's all very well, but these markers don't tell us anything about the date of the observation. To rectify this we could do:

          genr time
          genr year = 1960 + (5 * time)
          genr markers = "%s:%d", marker, year

The first line generates an index (1-based) representing the period of each observation and the second line uses the `time` variable to generate a variable representing the year of the observation. The third line contains the new feature: if the name of the new variable to generate is `markers` the portion of the command following the equals sign is treated specially. It is taken as C-style format string (which must be wrapped in double quotes), followed by a comma-separated list of arguments. The arguments will be printed according to the given format to create a new set of observation markers. Valid arguments are either the names of variables in the dataset, or the string `marker` which denotes the pre-existing observation marker. The format specifiers which are likely to be useful in this context are `%s` for a string and `%d` for an integer. Strings can be truncated: for example `%.3s` will use just the first three characters of the string. To chop initial characters off an existing observation marker when constructing a new one, you can use the syntax `marker +` n where `n` is a positive integer: in the case the first n characters will be skipped.

After the commands above are processed the observation markers will look like, for example, `AR:1965`, where the two-letter state code and the year of the observation are spliced together with a colon.