Hi all,
I have been spending hours trying to figure out a real simple problem, but I just can't seem to get it. As you can tell, I'm new to stata.
Background:
I have a variable taking values from 1 through 10, each corresponding to a specific 6month period. In order to make this more readable I apply a label to it, which I define as:
For code-flexibility I now want define this label in a loop (I will have MANY values later on, using different time-brackets), but I'm just don't understand how I best proceed with this.
Sought after solution:
I need a loop that creates a variable numberString containing the string
so that I later can run a command like
that would evaluate as
First step?:
I've tried almost uncountable variations, but found no solution. I assume the basic code would look something like
But I just can't seem to get it to work... Any ideas or help would be greatly appreciated!!
Kindly,
dalaij
I have been spending hours trying to figure out a real simple problem, but I just can't seem to get it. As you can tell, I'm new to stata.

Background:
I have a variable taking values from 1 through 10, each corresponding to a specific 6month period. In order to make this more readable I apply a label to it, which I define as:
Code:
label define lblName 1 "2005hy1" 2 "2005hy2" 3 "2006hy1" 4 "2006hy2" 5 "2007hy1" 6 "2007hy2" 7 "2008hy1" 8 "2008hy2" 9 "2009hy1" 10 "2009hy2"
Sought after solution:
I need a loop that creates a variable numberString containing the string
Code:
1 "2005hy1" 2 "2005hy2" 3 "2006hy1" 4 "2006hy2" 5 "2007hy1" 6 "2007hy2" 7 "2008hy1" 8 "2008hy2" 9 "2009hy1" 10 "2009hy2"
Code:
label define `numberString'
Code:
label define lblName 1 "2005hy1" 2 "2005hy2" 3 "2006hy1" 4 "2006hy2" 5 "2007hy1" 6 "2007hy2" 7 "2008hy1" 8 "2008hy2" 9 "2009hy1" 10 "2009hy2"
I've tried almost uncountable variations, but found no solution. I assume the basic code would look something like
Code:
local cnt 0 forvalues y = 2005/2009 { forvalues hy = 1/2 { // Append the string "`cnt' "`y'hy`hy'" to a local variable called numberString. But I don't know how to do this. How to get the quoutation marks in there, etc? local cnt = `cnt' + 1 } } label define `numberString'
Kindly,
dalaij
Comment