Hello,
I'm completly new to Stata and I couldn't find a solution for my basic problem, so I would be really thankful if someone can answer this short question:
I want to subtract to variables, they look like the following:
var1: var2
ID Freq. ID Freq.
1 145 1 435
2 278 2 234
3 543 3 643
4 683 4 123
And i want to subtract the frequencies to a new variable, so that the result will be:
var 3:
ID Freq.
1 435-145
2 234-278
3 ....
...
I tried using gen var3 = var2 - var1, but somehow then it subtracts the IDs and not the frequencies.
And I tried this:
gen var3 = .
replace var3 = 1 if var2 == 1
replace var3 = 1 if var1 == 1
But then it just sums up the frequencies, but I can't figure out how to subtract them.
I would really thankful for an answer!
Best Regards
I'm completly new to Stata and I couldn't find a solution for my basic problem, so I would be really thankful if someone can answer this short question:
I want to subtract to variables, they look like the following:
var1: var2
ID Freq. ID Freq.
1 145 1 435
2 278 2 234
3 543 3 643
4 683 4 123
And i want to subtract the frequencies to a new variable, so that the result will be:
var 3:
ID Freq.
1 435-145
2 234-278
3 ....
...
I tried using gen var3 = var2 - var1, but somehow then it subtracts the IDs and not the frequencies.
And I tried this:
gen var3 = .
replace var3 = 1 if var2 == 1
replace var3 = 1 if var1 == 1
But then it just sums up the frequencies, but I can't figure out how to subtract them.
I would really thankful for an answer!
Best Regards
Comment