Dear Colleagues,
I have a nice data set resembling the extract below.
Each of the variables corresponds to Deliberate fires (excluding chimney fires) per 100,000 population (for those interested in the subject that data is publicly available via the Scottish Neighbourhood Statistics). I'm using the code below to nicely label those variables:
The code would produce the the following labels.
I'm interested in doing something more fancy than that. For instance, I would like to have time periods expressed as 2009/10 not as 20092010 (alternatively 2009-2010). Ideally, would also like to automatically get the required figures in the substr command. Presently, I always look at the variable name and simply count the number figures but it would be wiser, and more efficient, to do this automatically. Ideally I'm looking to for a code where I would only have to provide the first part of the label (in this case: Deliberate fires (excluding chimney fires) per 100,000 population) and the years would be added to the variable label automatically. If it would be possible to implement a switch deciding how the year should be expressed (20092010 or 2009/10), this would be an added bonus.
I have a nice data set resembling the extract below.
Code:
clear input FRAccDwellFireRate20092010 FRAccDwellFireRate20102011 FRAccDwellFireRate20112012 FRAccDwellFireRate20122013 10 20 30 40 11 12 13 14 15 1 2 3 4 end
Code:
foreach var of varlist FRAccDwellFireRate* { label variable `var' /// `"Deliberate fires (excluding chimney fires) per 100,000 population: `=substr("`var'", 19, 8)' "' }
Code:
. codebook, compact Variable Obs Unique Mean Min Max Label -------------------------------------------------------------------------------------------------------------------------------------------- FRA~20092010 3 3 7.333333 1 11 Deliberate fires (excluding chimney fires) per 100,000 population: 20092010 FRA~20102011 3 3 11.33333 2 20 Deliberate fires (excluding chimney fires) per 100,000 population: 20102011 FRA~20112012 3 3 15.33333 3 30 Deliberate fires (excluding chimney fires) per 100,000 population: 20112012 FRA~20122013 3 3 19.33333 4 40 Deliberate fires (excluding chimney fires) per 100,000 population: 20122013 --------------------------------------------------------------------------------------------------------------------------------------------
Comment