Dear Stata List Members,
Would greatly appreciate it if any of you could provide some suggestions about the problem below:
I've about 41 variables (barriers to implementation of projects) which were collected at the pre and the post intervention phases. The variable naming convention is as follows: 'a1', 'b1', 'c1', ..., 'z1' which denote the pre values and 'a2', 'b2', 'c2', ..., 'z2' denote the post values, respectively.
I need to create new vars, 'predict' [a,b,c,...z], which would have a value of 1
if both the pre values and the post values for that barrier are equal to -1 OR one of them is -1 and the other is +3;
in other words,
if both 'a1' (i.e. pre values) and 'a2' (i.e. post values) are equal to -1 OR one of these vars is -1 (e.g., a1) and the other (e.g., a2) is +3. The process has to be repeated for all barriers.
Then for each team i.e. subject, I have to add all 'predict' vars (i.e. for each subject/team, create a sum of predict'a', predict'b', predict'c',..., predict'z').
Is there an efficient way to do this? I was reading about loops and macros which are new topics to me; I tried to use them, with my little knowledge gained through online searches but was unable to do so; not sure how to approach the problem. Would greatly appreciate any suggestion any of you might provide.
Below is what I did to complete the 1st step which is to generate 'predict' vars do but I got an error message that too many variables were specified. I'm also not sure how the 2nd step can be done- adding all 'predict' vars for each subject/team.
local cfir_intervention InterventionSource EvidenceStrengthQuality Relativeadvantage Adaptability Trialability Complexity DesignQualityandPackaging Cost
forvalues i=1/2 {
generate predict`cfir_intervention'=.
replace predict`cfir_intervention'=1 if cfir_intervention`i'==-1 & cfir_intervention`i'+1==-1
replace predict`cfir_intervention'=1 if cfir_intervention`i'==-1 & cfir_intervention`i'+1==3
replace predict`cfir_intervention'=1 if cfir_intervention`i'==3 & cfir_intervention`i'+1==-1
}
Thanks very much for your time.
Sincerely
Musarrat
Would greatly appreciate it if any of you could provide some suggestions about the problem below:
I've about 41 variables (barriers to implementation of projects) which were collected at the pre and the post intervention phases. The variable naming convention is as follows: 'a1', 'b1', 'c1', ..., 'z1' which denote the pre values and 'a2', 'b2', 'c2', ..., 'z2' denote the post values, respectively.
I need to create new vars, 'predict' [a,b,c,...z], which would have a value of 1
if both the pre values and the post values for that barrier are equal to -1 OR one of them is -1 and the other is +3;
in other words,
if both 'a1' (i.e. pre values) and 'a2' (i.e. post values) are equal to -1 OR one of these vars is -1 (e.g., a1) and the other (e.g., a2) is +3. The process has to be repeated for all barriers.
Then for each team i.e. subject, I have to add all 'predict' vars (i.e. for each subject/team, create a sum of predict'a', predict'b', predict'c',..., predict'z').
Is there an efficient way to do this? I was reading about loops and macros which are new topics to me; I tried to use them, with my little knowledge gained through online searches but was unable to do so; not sure how to approach the problem. Would greatly appreciate any suggestion any of you might provide.
Below is what I did to complete the 1st step which is to generate 'predict' vars do but I got an error message that too many variables were specified. I'm also not sure how the 2nd step can be done- adding all 'predict' vars for each subject/team.
local cfir_intervention InterventionSource EvidenceStrengthQuality Relativeadvantage Adaptability Trialability Complexity DesignQualityandPackaging Cost
forvalues i=1/2 {
generate predict`cfir_intervention'=.
replace predict`cfir_intervention'=1 if cfir_intervention`i'==-1 & cfir_intervention`i'+1==-1
replace predict`cfir_intervention'=1 if cfir_intervention`i'==-1 & cfir_intervention`i'+1==3
replace predict`cfir_intervention'=1 if cfir_intervention`i'==3 & cfir_intervention`i'+1==-1
}
Thanks very much for your time.
Sincerely
Musarrat
Comment