Hi, I was hoping somebody could help me - I am trying to hierarchically order var based on different portions of their names. I have data comprising var which are named according to the protein measured, the specific peptide assayed, the type of measurement and in some cases a suffix to denote a measure of variance. The data is in long format which is necessary due to this dataset being part of a much larger dataset where each observation corresponds to a particular ID.
For example, protein 'a' may have three different peptides measured ('1', '2' and '3'), each peptide would have three types of measurement ('i', 'ii' and 'iii'), and for each of those types of measurement, there would also be a measure of variance, denoted by the suffix '_cv'. This would correspond to 18 var as follows (in the desired order): a_1_i a_1_i_cv a_1_ii a_1_ii_cv a_1_iii a_1_iii_cv a_2_i a_2_i_cv a_2_ii a_2_ii_cv a_2_iii a_2_iii_cv a_3_i a_3_i_cv a_3_ii a_3_ii_cv a_3_iii a_3_iii_cv
I want the var to be ordered first by protein, then peptide, then measurement type, finally with each _cv value next to the measurement. In reality, the data is not ordered as I wish (all _cv values are at the end as were merged from a separate dta).
Here is an example dataset containing two proteins, a and b, with var in a random order (the actual dataset contains a large number of observations and var):
I have the following code to list all var names excluding the variables plate and id:
However, I am unsure how to reference the specific protein/peptide/measurement type for ordering?
I would be very grateful for some guidance!
Many thanks,
Liz
For example, protein 'a' may have three different peptides measured ('1', '2' and '3'), each peptide would have three types of measurement ('i', 'ii' and 'iii'), and for each of those types of measurement, there would also be a measure of variance, denoted by the suffix '_cv'. This would correspond to 18 var as follows (in the desired order): a_1_i a_1_i_cv a_1_ii a_1_ii_cv a_1_iii a_1_iii_cv a_2_i a_2_i_cv a_2_ii a_2_ii_cv a_2_iii a_2_iii_cv a_3_i a_3_i_cv a_3_ii a_3_ii_cv a_3_iii a_3_iii_cv
I want the var to be ordered first by protein, then peptide, then measurement type, finally with each _cv value next to the measurement. In reality, the data is not ordered as I wish (all _cv values are at the end as were merged from a separate dta).
Here is an example dataset containing two proteins, a and b, with var in a random order (the actual dataset contains a large number of observations and var):
Code:
clear input plate id b_2_i b_2_i_cv b_2_iii b_1_ii b_1_ii_cv b_1_iii b_1_iii_cv a_3_ii_cv b_2_ii a_3_iii b_2_ii_cv a_1_ii b_3_i_cv b_3_ii b_3_ii_cv b_3_iii b_3_iii_cv a_3_i a_3_i_cv b_2_iii_cv b_3_i a_2_ii_cv a_2_iii a_2_iii_cv a_3_iii_cv b_1_i b_1_i_cv a_3_ii a_1_i a_1_i_cv a_1_ii_cv a_1_iii a_1_iii_cv a_2_i a_2_i_cv a_2_ii 1 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . end
Code:
local vars `r(varlist)' unab omit: plate id local measures : list vars - omit
I would be very grateful for some guidance!
Many thanks,
Liz

Comment