I'm working with a data set resembling the extract below:
I would like to apply the following transformations to this data:
I'm thinking that the pseudocode would look like that:
Code:
clear set obs 10 generate var2000 = runiform() generate var_2001 = runiform() generate ind20032004 = runiform() generate ind_20032004 = runiform() generate ind65somthing_2005 = runiform() generate ind65something2006 = runiform()
- Select variables that do not have the underscore sign in the variable name and ignore variables that have the underscore in the name already present
- Add the underscore sign before the last set of digits; the generated variable names should resemble the table below:
Current variable name | New variable name | Change |
var2000 | var_2000 | Underscore sign added |
var_2001 | var_2001 | No change |
ind20032004 | ind_20032004 | Underscore sign added |
ind_20032004 | ind_20032004 | No change |
ind65somthing_2005 | ind65somthing_2005 | No change |
ind65something2006 | ind65something2006 | Underscore sign added |
I'm thinking that the pseudocode would look like that:
PHP Code:
IF sign "_" does not exist then
find the_last_set_of_digits and get length and insert "_" before
ELSE
ignore
Comment