# improving my variable names

Good variable names are:

a) short / easy to type,

b) easy to remember,

c) understandable / communicative.

Am I forgetting anything? Consistency is something to look for. The way I would put it is that consistent naming conventions contribute to the qualities above. Consistency contributes to (b) ease of recall and (c) understandability, though other factors are often more important. There is a clear tradeoff between (a) name length / ease of typing (e.g. all lowercase) and (c) understandability.

I'm investing a fair bit of thought in these issues because thousands of people are using the data and I hope many will use my code to prepare the data and facilitate some types of analysis. The data, from the Longitudinal Study of Adolescent Health, is broken down into multiple datasets. My first step was to take the 227 variables in the most commonly used dataset, recode them, give them more meaningful names. Original variable names are things like "aid", "s1", "s2", which I renamed "aid2", "age", and "male.is". There are thousands of other variables in the other datasets which may be merged depending on what the researcher's goals are.

As long as I'm renaming variables, I want to make them as useful as possible. Here are some of the issues I've considered. So far, I have only used lower-case and avoided using any dashes or underscores, and I've only used periods for one very specific purpose. This has the virtue of simplicity and consistency, and causes no problems for most variables. But as things get more complex I'm tempted to break my consistency. Take, for example, my variable "talkprobmsum", it would be easier to read as "talkProbMSum" or better still "talk.prob.m.sum", but if I'm going to use capital letters or periods to separate words then shouldn't I do it for all variables?

Some variables are recorded at more than one time, e.g. the race variables so I appended .is or .ih to indicate whether they come from the in-school or in-home questionnaire. But there are surely some repeats I'm not aware of yet, would it be better to append a reference to the dataset to the name of every variable?

I need to group-center and standardize a lot of variables, the way I've done that is by appending .zms meaning z-score by male and by school.

Any general or specific thoughts or resources are greatly appreciated. See this repository for some of my code, and descriptive statistics with a list of variable names. I briefly described the reason for sharing this code here, and it was publicized a bit here, but these last two links aren't really relevant to the issue of variable naming conventions. Added: I edited this lightly, mostly just moving a paragraph, to try to avoid some of the confusion evident in the comments. Thanks for thoughts!

-
+1 for setting up a public repository to share amongst researchers, although this question really belongs to Stack Overflow. – nico Apr 18 '12 at 17:28
Why would this question be better on SO, @nico? To me it does not appear to be about programming or even about R, but rather about appropriate practices for documenting and using data. – whuber Apr 18 '12 at 17:39
@whuber: I get your point. However, reading the question I saw it as "how should I call my variables?", which to me sounds more like a programming matter and not about statistics... On second thought, it is also true that the audience here is closer to that which will use the actual data than that of SO. – nico Apr 18 '12 at 18:13
+1, I think this is a great question & kudos for doing this – gung Apr 19 '12 at 2:41

There are various R packages providing this machinery, e.g. Hmisc which you use, and memisc. But really the best option is to make the whole thing into an R package. That way the processed data can be an object with a corresponding help page that describes what everything is now called and can assign credit where it's due. The package can also expose the raw data and your processing functions for people to see what you did to make the final product.