Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to loop labels?

    Hello Stata users!

    This is also my first post and I basically am looking for an easier way to code labels.

    So I have a data base that has the same information for different animals.

    So our list of animals is: cow, bulls, chickens, buffalos, and sheep.

    We have information about each animal: number of (animal) farmer own, number of (animal) bought, number of (animal) sold, and number of (animal) died.
    The variables are coded the following way :
    First by type of information so for example, number of (animal) owned is coded as q1, bought is q2, etc.
    Each animal is coded as a1 (cows), a2 (bulls) etc.

    So our variable list is q1_a1; q1_a2;….. q2;_a1 etc.
    Where q1_a1 is number of cows a farmer owns, q1_a2 number of bulls a farmer owns, q2_a1 number of cow that were bought. I have a problem with the labeling:

    I am now labeling each of them and I am doing the following:
    label variable q1_a1 “Q1.A1 Number of cows owned by Farmer”
    label variable q1_a2 “Q1.A2 Number of bulls owned by Farmer”
    This seems like a waste of time… I know how to use forvalues to change the labels such as:

    Code:
    forvalues x=1 (1)  5  {
    label variable q1_a`x' "Q1.A `x' Number of (animals) owned"
    }
    But in this case where (animals) is, I would like stata to put the animal. Such that it looks like "Q1.A1 Number of cows owned" in the label.

    Is there a way to do this through a loop?

    I hope this is clear!!

    Thank you so much!

Working...
X