Hello,
I have biannual files called "job_history" with a year suffix at the end (job_history_1992, job_history_1994, etc.). Within each of these files, I have 65 "state" variables with suffix at the end, from state1 to state65. I want to add, within each file, the year suffix to the name of the "state" variables. So, for 1992, I would have state1_1992, state2_1992, etc.
I am trying to do it with the following loop:
foreach data in job_history_1992 job_history_1994 job_history_1996 job_history_1998 job_history_2000 job_history_2002 job_history_2004 job_history_2006 job_history_2008 job_history_2010 job_history_2012 job_history_2014 job_history_2016 job_history_2018 {
local i = substr("`data'", 13, .)
foreach var of varlist state1 state2 state3 state4 state5 state6 state7 state8 state9 state10 state11 state12 state13 state14 state15 state16 state17 state18 state19 state20 state21 state22 state23 state24 state25 state26 state27 state28 state29 state30 state31 state32 state33 state34 state35 state36 state37 state38 state39 state40 state41 state42 state43 state44 state45 state46 state47 state48 state49 state50 state51 state52 state53 state54 state55 state56 state57 state58 state59 state60 state61 state62 state63 state64 state65{
rename `var' `var'_`i'
save, replace
}
}
And I am getting the following error: state1 ambiguous abbreviation (see below)
Is it because variables have identical names across files? How would I solve this issue?
Thank you so much!
-Lucia
Array
Related Posts with Rename variables within loop - ambiguous abbreviation error
Seconds base date & Differing units of analysis: Generate variable containing differences between first and last second of a unitDear all, I am trying to work my way into stata and I read a lot about how to build differences, bu…
About the 2-Step weighting matrixDear Statalisters, I've two questions about the weighting matrix in two-step GMM. Theoretically the…
Keeping a list of observations using foreachCan foreach be used to keep a group of observations of a specific variable? I need to keep a group …
Merge with duplicates in the using data setHi, I would like to merge two data sets. Dataset A contains the values of the variable x. Among them…
Low amount of clusters should I use vce(cluster) in my xtivreg?Hey, I have a panel data with instrumental variables, therefore I am using xtivreg with random effe…
Subscribe to:
Post Comments (Atom)
0 Response to Rename variables within loop - ambiguous abbreviation error
Post a Comment