I am trying to replace my variables with names in first row that seem to be long.
I want to first derive the first 14 characters in the string in row 1, then use the returned string to replace the variable names.
When I do that, I get an error "variable newvars not found".
Kindly assist
Here is my code:
I want to first derive the first 14 characters in the string in row 1, then use the returned string to replace the variable names.
When I do that, I get an error "variable newvars not found".
Kindly assist
Here is my code:
Code:
foreach var of varlist * { local names "`=`var'[1]'" foreach x of local names{ replace `x' = substr(`x', 1, 14) } }
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str18 _varname str49 _var1 str44 _var2 str55 _var3 str56 _var4 "newvars" "seed_yam_multiplication_tech_Bono_East_Oti_farmer" "seedbed_options_ridging_Bono_East_Oti_farmer" "stress_tolerant_improved_varieties_Bono_East_Oti_farmer" "disease_and_pest_tolerant_varieties_Bono_East_Oti_farmer" "cs_score_prod" "1" "4" "4" "4" "cs_score_adapt" "3" "3" "4" "3" end
Comment