Dear all,
I tried to find a solution in other posts but I couldn't find what I need.
I have a panel data with the same information collected in many years and each year is presented as a variable, so I need to reshape.
To reshape the data, I need the year to appear in the var name, but it does not, the year appears only in the label.
So, I tried to rename the vars using the label as follows:
but I got an error.
My data is confidential, so here is only the presentation of some variables with their labels, without the values:
Can you please help.
Best
I tried to find a solution in other posts but I couldn't find what I need.
I have a panel data with the same information collected in many years and each year is presented as a variable, so I need to reshape.
To reshape the data, I need the year to appear in the var name, but it does not, the year appears only in the label.
So, I tried to rename the vars using the label as follows:
Code:
foreach var of varlist _all{ local current_lab: variable label `var' local ncl = strlower("`current_lab'") local ncl = ustrregexrf("`ncl'", "-* ", "") local ncl = ustrregexrf("`ncl'", " \([^)]*\)", "") local ncl = ustrregexra("`ncl'", " ", "_") display "`ncl'" rename `var' `ncl' destring `ncl', replace }
Code:
syntax error Syntax is rename oldname newname [, renumber[(#)] addnumber[(#)] sort ...] rename (oldnames) (newnames) [, renumber[(#)] addnumber[(#)] sort ...] rename oldnames , {upper|lower|proper} r(198);
My data is confidential, so here is only the presentation of some variables with their labels, without the values:
- _v* are the current var names. What is shown in front of these _v* are the labels:
- for example: _v1 is the var name and "Memo1 - some words (UF) (1990)" is what I see in the label column in Stata:
Code:
_v1 Memo1 - some words (UF) (1990) labels7 _v2 Memo1- some words (UF) (1991) labels8 _v3 Memo1- some words (UF) (1992) labels9 _v4 Memo1- some words (UF) (1993) labels10 _v5 Memo1- some words (UF) (1994) labels11 _v6 Memo1- some words (UF) (1995) labels12 _v7 Memo1- some words (UF) (1996) labels13 _v8 Memo1- some words (UF) (1997) labels14 _v9 Memo1- some words (UF) (1998) labels15 _v10 Memo1- some words (UF) (1999) labels16 _v11 Memo1- some words (UF) (2000) labels17 _v34 Memo1- some words (1990) labels40 _v35 Memo1- some words (1991) labels41 _v36 Memo1- some words (1992) labels42 _v37 Memo1- some words (1993) labels43 _v38 Memo1- some words (1994) labels44 _v39 Memo1- some words (1995) labels45 _v40 Memo1- some words (1996) labels46 _v41 Memo1- some words (1997) labels47 _v42 Memo1- some words (1998) labels48 _v43 Memo1- some words (1999) labels49 _v44 Memo1- some words (2000) labels50
Can you please help.
Best
Comment