Is there any way to label dummy variable in Excel? - excel

The following column contains a dummy variable for gender:
gender
1
0
2
0
where 1 is male, 2 is female, 0 is unknown.
I want to assign labels to the values, like in Stata, so that when I construct a chart, the legend would show Male instead of 1. Also, it would be nice if the dataset depicted string Male, but assumed value 1 for calculations.
How can I do that?

What you want is not (as far as I know) supported in Excel. What you need is sort of an ID value and a display value as is commonly known from DB-oriented controls like a Listbox in Access or the like. This does not exist in a single Excel cell, you'd have to simply make another column or replace the values.
BUT...
In this specific case you could reach the goal with the following 'hack':
The cells' numberformat supports different format strings for positive and negative values and for 0. For your three-valued-logic, you could make use of that, but you'd have to change your IDs to 1, 0 and -1. Then use "Male";"Female";"Unknown" as a custom format string.
... if this does not work, rather use a seperate column with a simple formula.

Related

Display text different to actual value when actual value is *

That's basically it.
I have a * in some cells to represent "All" data, because I need it for some formulas later, but I want to use it in the titles so it would be nice if it could display "Total" but still maintain the * below.
As you can see from the picture, the cell should be showing "Total" (red arrow) while mantaining the vale as "*" (blue cirlce).
Tried a few tutorials but nothing seems to work, I'm not sure if it's because it's an asterisk or what.
Edit: the tutorial I mostly followed is this one, in my case instead of 1,2,3,4,etc I have * (aka the value) and I want to display "Total" instead.
Custom number formats in Excel split into four categories:
Positive values
Negative values
Zero values
Text values
* is a text value so you want the fourth category and you get this by inserting semicolons before the required format to indicate that 1, 2 and 3 don't apply so you end up with:
;;;"Total"
where A2 and A4 actually contain an asterisk.
You have cells that have contents X but you want Excel to say, "no, no. I'm going to show you Y"?
Aside from sounding like a maintenance nightmare, I am not aware of a way to do that.

How to replace numbers with corresponding text values in Excel without making it treat a number individually?

Okay, so here's the thing. I have a list of compounds which are listed as compound_1,compound_2,compound_3 and so on. I would like to change it to the corresponding compound names using Excel. There are over 140 compounds and in the datatable, the compound repeats itself for a number of times.
The problem arises when the Excel treats two digit numbers as two individual numbers instead of treating them as a one whole unit and substitutes value accordingly. I'll give you an example. Say, compound_2 is Nicotine and compound_20 is quercetin, it treats 20 as 2 and 0, and the cell is replaced with Nicotine0 instead of quercetin.
Is there a way to replace it without this hassle?
P.S: The table looks something like this:
compound_1 Nicotine
compound_2 β- sitosterol
compound_3 D - mannitol
compound_4 Stigma Sterol
compound_5 Betulinic Acid
And, I've attached a collage comparing the column values before(left) and after(right) I tried replacing compound_2 with Nicotine.(This is only for example and not the real pair)image

Scorecard Question Part 1 - multiple IFs formula

my challenge is of 2 parts (2nd part was already responded by Michal Rosa and Lee Mac).
Here is part 1:
I am working on a scorecard which has series of references. I initially wrote a series of Nested IFs which was very long and also is tedious to change especially when targets change. How can I hardcode or create a formula where I can just change the targets/scoring matrix on the table
Please see sample data:
KRA Data
Say if the agent's LOB is Email, and is in a tenure of 61-90 Days, we return corresponding KRA Rating from the KRA Rating Matrix depending on Actual Score. Like for Agent 1, her Actual Closure score is 18.55 and corresponding KRA rating for her tenure of 61-90 Days is 4.
Similarly, for her TPH, her Actual TPH is 7.02, which assigns a KRA Rating of 3 in the Scorecard Rating Matrix.
You can use nested INDEX / MATCH :
For the outer one (i.e. the one that will find the rating), you use a MATCH which will match the nearest value in the table that is still less than value. You have to modify the look of your rating matrix, instead of putting 4.5 - 5.5, you have to put a single value, i.e. 4.5. You always start with the lowest possible value (typical 0 or minus something), and you end with the highest value.
With the inner one, you extract the array (row) from your matrix that matches both criteria (tenure and LOB), and this array will be fed into the outer match. As it is now, you have to use two formula's, one for the TPH and one for the closure. If your KPI would not be in merged cells, but on each row (like for Tenure and LOB), you could add another condition in the inner MATCH and do everything with a single formula.
The array formula (ctrl+shift+enter) is like this:
{=INDEX($C$1:$F$1;MATCH(D9;INDEX($C$2:$F$5;MATCH(1;($A$2:$A$5=$A9)*($B$2:$B$5=B9);0););1))}
This is a screenshot, starting from A1 (Tenure) and with the formula in F9. I used the colors of your spreadsheet to make it more visual.
This is the same formula with the cell and range references replaces by text so you can better understand and replace with the correct ranges of your worksheet. I hope it is self-explanatory, otherwise just ask:
=INDEX(The_rating;
MATCH(closure-rate_value;
INDEX(Matrix_with_closure-rate_cutoffs;MATCH(1;(LOB_column=LOB_value)*(Tenure_column=Tenure_value);0););1))

Using MIN function in excel when using mm:ss.00 fields and ignoring 00:00.00

Does anyone know how I can get excel to look at the following fields, all formatted in mm:ss.00 and return the lowest time. I am using this to calculate PB's - personal best times - in a sports club race sheet.
The formula I am using is
=MIN(J5,(U5),(AE5),(AO5),(AY5),(BI5),(BS5),(CC5),(CM5),(CW5),(DG5),(DQ5),(EA5),(EK5),(EU5))
The problem I have at the moment is that it is including 00:00.00 values in the cells and returning a MIN value of 00:00.00.
Any suggestions would be welcomed.
many thanks
Nigel
Use the following:
=SMALL((J5,U5,AE5,AO5,...),COUNTIF((J5,U5,AE5,AO5,...),0)+1)
COUNTIF counts the amounts of 0 (you maybe need to adjust this value based on your formatting, but it should work). SMALL returns the n-smallest number of the given matrix, with n being the counted value + 1.
Therefore if no 0 is in the matrix, you get the 1st-smallest (aka the smallest), with one 0 you get the 2nd-smallest and so on. Maybe you need to add a check if every value is 0, if that could happen, as in that case SMALL would try to retrieve the value on position list_size+1 of the list, which of course isn't present.

Excel: Replace strings with numbers in a formula?

I have color strings in one of my columns, like red, purple and so on. I want to replace those colors with corresponding numbers. Red becomes 1, purple becomes 2 and so on.
Thats not so hard, I used substitute, like this:
SUBSTITUTE(E3;"red";"1")
Now the problem ist that some columns have 2 or more colors, like "red purple", so I tried using:
SUBSTITUTE(E3;"red";"1")&SUBSTITUTE(E3;"purple";"2")
That results in a value in my column that looks like 1red, There is the color from that row attached for each &SUBSTITUTE I add. If I added another color, like that
SUBSTITUTE(E3;"red";"1")&SUBSTITUTE(E3;"purple";"2")&SUBSTITUTE(E3;"green";"3")
it would become 1redred.
How can I solve this issue? I want to replace each color string with its corresponding number.
Thanks!
Try this
=SUBSTITUTE(SUBSTITUTE(E3,"Purple","2"),"Red","1")
Please consider the following more compact solutions (assuming tested cell is A2):
Using MATCH: if you need to return sequenced numbers like 1, 2, 3 ... - this formula will do the job:
=IFERROR(MATCH(A2,{"Red","Green","Blue"},0),"UNKNOWN COLOR")
You may add a multiplier / constant to the returned value as well. Order in sequence of strings equals the number returned.
Using VLOOKUP: if you need some defined set of returned values - define them in 2-dim array constant:
=IFERROR(VLOOKUP(A2,{"Red",10;"Green",20;"Blue",30},2,0),"UNKNOWN COLOR")
For this example 10, 20 and 30 will be returned.
Both formulas include error handling for unspecified colors.
Sample file is shared: https://www.dropbox.com/s/77aj1vl6c5gek5c/ColorsLookup.xlsx
P.S. I'm not sure about correct array dimension delimiters, since my local settings use different ones, but in sample file formulas work fine.

Resources