Hello. I have a question about automating the variable labeling process. Below is my fictional dataset with my variables and the variable labels. The dataset originally came from a very messy csv file. When you try to run the code below, the variable labels has this weird character â€" and will produce an error code when you try to reproduce my data. You will have to go to the GUI and manually paste it in but I provided code to illustrate how my dataset looks like.
We are deciding how to create variable labels. There are two options to relabeling the variable labels:
1)How would I keep everything before â€" symbols in the variable label? For example for the variable bl_instruct_sal,, the variable label would be "Object Code 1000"
2) How would I keep everything between â€" and the *: symbol? For example, for the variable bl_instruct_sal, the variable label would be "Instructional Salaries"
I tried this approach to delete out the word "Object Code" but I don't know how to delete out this †symbol.
Thank you so much for your feedback and help.
We are deciding how to create variable labels. There are two options to relabeling the variable labels:
1)How would I keep everything before â€" symbols in the variable label? For example for the variable bl_instruct_sal,, the variable label would be "Object Code 1000"
2) How would I keep everything between â€" and the *: symbol? For example, for the variable bl_instruct_sal, the variable label would be "Instructional Salaries"
I tried this approach to delete out the word "Object Code" but I don't know how to delete out this †symbol.
Code:
foreach v of varlist bl_* {
local lbl: var label `v'
local lbl: subinstr local lbl "Object Code" "", all
label var `v' `"`lbl'"'
}
Thank you so much for your feedback and help.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input long(bl_instruct_sal bl_non_instruct_sal bl_employ_bene bl_supply_materials bl_o_oper_expenses bl_capital_outlay bl_o_outgoing) 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 end label var bl_instruct_sal "Object Code 1000 â€" Instructional Salaries*:How were Promise Grant funds alloca" label var bl_non_instruct_sal "Object Code 2000 â€" Non-Instructional Salaries*:How were Promise Grant funds al" label var bl_employ_bene "Object Code 3000 â€" Employee Benefits*:How were Promise Grant funds allocated b" label var bl_supply_materials "Object Code 4000 â€" Supplies and Materials*:How were Promise Grant funds alloca" label var bl_o_oper_expenses "Object Code 5000 â€" Other Operating Expenses and Services*:How were Promise Gra" label var bl_capital_outlay "Object Code 6000 â€" Capital Outlay*:How were Promise Grant funds allocated by b" label var bl_o_outgoing "Object Code 7000 â€" Other Outgoing*:How were Promise Grant funds allocated by b"

Comment