Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 65037

Removing leading 0's in variable names to convert wide form to long form panel data

$
0
0
Hello,

I'm quite frustrated with a few different efforts I have made to convert my variables from wide-form to long-form.

I have a labour panel database that has over 800 variables for 3 waves. Variables are noted var_98 var_06 var_14. When converting to long form I get a warning that stata cannot find var_6.

From reviewing other's requests, I see that the leading 0 is an issue for stata and am trying to find ways to remove it without manually typing all the variables in my do file.

So essentially this would mean converting all var_06 = var_6. I see that some have suggested using substring and subinstr but I get mismatch errors, and am not sure if this only does apply to the variable name rather than the actual name of the variable.


foreach stub of varlist gov_06-RmnthwgAllJobCPI12_06 {
2. local newname = substr(`stub', 1, length(`stub')-1) if substr(`stub',-1,1)
> =="0"
3. rename `stub' `newname'
4.
. }

type mismatch
r(109);

Secondly, if possible I would prefer that it just applies to the entire list whenever the final two numbers are 06. Could someone let me know if they have tips on solving this?

Michelle

Viewing all articles
Browse latest Browse all 65037

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>