Hi there,
I am trying to retrieve the value labels for the encoded variable pos_index (defined below) in a forvalues loop to determine the correlation, split by the four levels of pos_index, between two numerical variables. I wish to display the category before the cross-correlation table for each level but I am unable to do so. Any help would be greatly appreciated.
Code:
encode position, gen (pos_index) lab def pos_label 1 "Defenders" 2 "Forwards" 3 "Goalkeepers" 4 "Midfielders" lab val pos_index pos_label forvalues i in 1/4 { display "`i'" pwcorr age caps if pos_index == `i' } This obviously only displays 1,2,3 and 4 but I'm looking for the amendment to this code that would help me display the corresponding value label from pos_index.
Also as a sidenote, is there any way for me to incorporate in the first line of the forvalues command itself, a reference to the levels of the variable that I would like to loop over?
Something in the ilk of -
Code:
foreach i in levels(pos_index) { display "`i'" pwcorr age caps if pos_index == `i' } This particular code gives me a syntax error but the the correct version of this would allow Stata to directly pick up the distinct levels in the variable of interest as opposed to me explicitly specifying them.
Note: I am aware of the levelsof(var), local() command but that too only displays the numeric code as opposed to the label.
Any help would be greatly appreciated.
Thank you in adavnce,
Yash
Related Posts with Viewing value labels in a loop
Meta-Analyses-HeterogeneityHello, I ran a pairwise meta-analyses in STATA and i found high level of heterogeneity, so i want to…
Paneldata with feDear Statalists, I'm using a panel dataset on U.S. imports to the EU including tariff changes for s…
How to calculate median of 5 year Age category of 15-49 year women sample in DHSDear Statalist May I request how to calculate for Median of 5 year age category of 15-49 year women…
System GMM and fixed effectsDear all, I am trying to estimate a model for panel data and I was thinking about using System GMM. …
MimrgnsHi I'am trying to obtain margins after MI estimate and test differences between each slopes by a gro…
Subscribe to:
Post Comments (Atom)
0 Response to Viewing value labels in a loop
Post a Comment