# st: AW: RE: AW: how to reconstruct a minimum acceptable income from a set of binary variables?

 From "Martin Weiss" To Subject st: AW: RE: AW: how to reconstruct a minimum acceptable income from a set of binary variables? Date Sun, 1 Mar 2009 20:55:08 +0100

```<>

Yet another variation, playing around with -mata-

*************
clear*
input id mindesinc_500_999 mindesinc_1000_1499  mindesinc_1500_1999
101 1 0 0 0
102 0 1 0 0
103 0 0 1 0
104 0 0 1 0
105 0 1 0 0
end

mata
// get view onto the data
st_view(X=.,., (" mindesinc_500_999", " mindesinc_1000_1499", "
mindesinc_1500_1999"))
// column vector of lower bounds for minimum desired income
Y=(500\1000\1500)
// calculate vector of lbs for each individual
Z=X*Y
// need new var for minimum desired income
//push results back to newly created Stata variable
st_store((1,5),"mindesinc",Z)
end

* back in Stata, let`s see
l
*************

On the occasion, does Stata not color lines in red in the review window that
resulted in errors in -mata-? That would be useful...

HTH
Martin

-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Nick Cox
Gesendet: Sonntag, 1. März 2009 20:32
An: statalist@hsphsun2.harvard.edu
Betreff: st: RE: AW: how to reconstruct a minimum acceptable income from a
set of binary variables?

A variation on the same idea:

gen min = 500

foreach v in 1000 1500 2000 {
replace min = `v' if mindesinc_`v' == 1
}

To be careful, check

egen row = rowtotal(mindesinc*)
assert row == 1

Nick
n.j.cox@durham.ac.uk

Martin Weiss

*reconstruct Ekaterina`s data
clear*
input id mindesinc_500_999 mindesinc_1000_1499  mindesinc_1500_1999
101 1 0 0 0
102 0 1 0 0
103 0 0 1 0
104 0 0 1 0
105 0 1 0 0
end
*construct the minimum desired income
g mindesinc=500 if mindesinc_500_999
replace mindesinc=1000 if mindesinc_1000_1499
replace mindesinc=1500 if mindesinc_1500_1999
l

Ekaterina Hertog
I am dealing with a dataset from a private company and so my data often
comes in rather strange format and I now came against the following
problem:

I have a set of individuals who answered questions about desired income.

It looks as follows:

Individ nmb | Min desired income 500 - 999 | 1000 - 1499 |  1500 - 2000
|
101             |                      0
|         0          |           1          |
102             |                      0
|         1          |           1          |
103             |                      0
|         0          |           1          |
104             |                      1
|         1          |           1          |
105             |                      0
|         1          |           1          |

Is there a way to automatically recode these binary minimum desired
income variables into a numerical variable which would state the minimum

acceptable figure for each individual?
That is some routine which would check "Min desired income 500 - 999"
and if it equals 1 then would input 500 for the individual in question
into a newly constructed variable "Minimum acceptable income" and move
on to the next person and if it equals 0 would look at the value of
"1000 - 1499" variable and if it equals 1 would input 1000 for that
person and move on to the next person and if it is 0 would look at "1500

- 2000" variable?

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```