-1

Please correct my code so that the new variable takes on value 1 if column treatment ==1 and column category_assetprovision =="Accepted" and it takes on the value 0 if column treatment ==0 & column category_assetprovision =="Refused" in Stata.

gen treatmentBreakdown = 1 if treatment ==1 & category_assetprovision =="Accepted" and 0 if treatment ==0 & category_assetprovision =="Refused"

Please correct my code so that the new variable takes on value 1 if column treatment ==1 and column category_assetprovision =="Accepted" and it takes on the value 0 if column treatment ==0 & column category_assetprovision =="Refused" in Stata.

gen treatmentBreakdown = 1 if treatment ==1 & category_assetprovision =="Accepted" and 0 if treatment ==0 & category_assetprovision =="Refused"
Nick Cox
  • 35,529
  • 6
  • 31
  • 47

1 Answers1

1

Guessing what the code might be or what you would like it to be is a poor way to learn the syntax of any language.

What is best here depends on what other possibilities exist. Cautious code for the first might be

gen treatmentBreakdown = . 
replace treatmentBreakdown = 1 if treatment ==1 & category_assetprovision =="Accepted" 
replace treatmentBreakdown = 0 if treatment ==0 & category_assetprovision =="Refused"

and then the second problem is similar and has a similar solution.

Note that

treatment == 0 & category_assetprovision =="Accepted" 

treatment == 1 & category_assetprovision =="Refused"

would both be mapped to missing (.) by this code, as would any other two values of those two variables not yet mentioned.

Stata does not support and as an operator and it allows only one if qualifier in any statement that allows if at all.

Nick Cox
  • 35,529
  • 6
  • 31
  • 47