Cant get my if Statement to work correctly - if-statement

I'm trying to make it so that when X is selected it then calls another set of code. for example
Main Selection is Type of Settlement( 4 choses ) City2, Village, Town, Hommlet. this is in a drop down in a Name Range. however this really isn't linked to anything, and should affect any of the other outcomes.
part 2 :
=SORTN('Data Sheet'!D5:E17,1,0,'Data Sheet'!E5:E17,FALSE)
Here i have it select from a list of Races ie Human, Dwarf, Elf Ect. along with a % of chance that Race is selected. there are 3 types that will pop up and some other formulas for calculated % of each.
Hommlet TRUE
| Hommlet TRUE
What Type of Settlement?
Population 54
Races and Purcentage Within the Setttlement
% Race # of
Majority Race 91 Half-elf 99 49
Secondary Race 6.03 Genasi 3
Tertiary Race 2.97 Firbolg 97 1.6
3rd on and here is where the issue is. If the Race is "Human" THen is needs to pick from a 'list of Human names. A data base list of name i have.
=If(N7="Human",INDEX('Name Lists'!B2:B15,RANDBETWEEN(1,COUNTA('Name Lists'!B2:B15))),"None")
here is the test i did to insure it would work before i embedded more into the the If formula. i also did a logic test to see if when Human Appeared it would come back TRUE, but it always returns False. if I type the word Human in another cell and Direct above code to that cell it works.
check out thew above

Related

How do I create a non mutually exclusive categorical variable?

In Stata I am analyzing a study looking at pre-existing conditions that participants may have had that affect whether they experience side effects after vaccination.
For each participant, there are three binary variables that denote whether the participant had that condition (0: does not have, 1: does have), namely hypertension: 0/1, asthma: 0/1, diabetes: 0/1.
However, these categories are not mutually exclusive as the participant can have any combination of conditions: (no pre-existing conditions, only hypertension, only asthma, only diabetes, hypertension and asthma, hypertension and diabetes, asthma and diabetes, hypertension and asthma and diabetes).
I would like to perform a regression analysis to determine the risk of developing side effects given exposure to pre-existing conditions and to create a variable denoting the different combinations.
I would like to get the risk ratios for the following table:
Type of pre-existing condition
With side effects
no side effects
risk ratio
None
455
316
ref
Hypertension
51
28
Asthma
42
26
Diabetes
17
7
Does anyone havecode that would help in creating a new categorical variable to help with this regression analysis?
I've tried using the following code, but because the categories are not mutually exclusive, the values assigned overwrite each other. new_var denotes the new variable created denoting the pre-existing conditions.
generate new_var = 0
replace new_var = 1 if hypertension == 1
replace new_var = 2 if asthma == 1
replace new_var = 3 if diabetes == 1
This is as much statistical as Stata-oriented, but there is a Stata dimension, so here goes.
#Stuart has indicated some ways of getting composite variables in Stata, but as no doubt he would emphasise too, watch out that the numeric coding is arbitrary and not to be taken literally.
Other methods of creating composite variables were discussed in this paper and that advice remains valid.
That said, I suspect most researchers would not use a composite variable here at all, but would use as predictors the three indicators you already have and their interactions. That is the only serious and supported method to get estimates of effect size together with appropriate tests.
There are 8 possible combinations of preexisting conditions, and one approach is to add the variables like this, then manually label them:
generate new_var = hypertension * 4 + asthma * 2 + diabetes
label define preexisting 0 none 1 diabetes 2 asthma 3 "asthma and diabetes" 4 hypertension 5 "hypertension and asthma" 6 "hypertension and diabetes" 7 "hypertension, asthma and diabetes"
label values new_var preexisting
If you have additional preexisting condition variables, multiply them by 8, 16, 32 and so on to get unique values for every combination.
Another approach is to use interactions in the regression.
regress outcome hypertension##asthma##diabetes

Making two IF statements in a manual input cell which reference two different cells

Currently, I have Data Validation for cell E4, stating formula =IF(E4>1,””,1). This prohibits the user from entering any number other than 1 or zero.
I need the user to manually enter the number “1” in cell E4 if a particular action is accomplished (a numerical checkbox, essentially).
I also want the value of cell E4 to read “1” if cell B4 reads the number “3”.
I’ve read several examples of nested IF statements and can’t find any that reference two different cells to decide the value of another cell.
Can I make nested IF statements in Data Validation? I haven’t been successful in doing so.
The two formulas I need to affect cell E4 are;
IF(E4>1,””,1)
and
IF(B4=3,E4=1,””)
Any help is much appreciated.
You just need an OR statement.
=IF(OR(E4 > 1, B4 = 3),””,1)

Creating an ID based on factor and filling down with Stata

Consider the fictional data to illustrate my problem, which contains in reality thousands of rows.
Figure 1
Each individual is characterized by values attached to A,B,C,D,E. In figure1, I show 3 individuals for which some characteristics are missing. Do you have any idea how can I get the following completed table (figure 2)?
Figure 2
With the ID in figure 1 I could have used the carryforward command to filling in the values. But since each individual has a different number of rows I don't know how to create the ID.
Edit: All individual share the characteristic "A".
Edit: the existing order of observations is informative.
To detect the change of id, the idea is to compare if the precedent value of char is >= in each rows.
This works only if your data are ordered, but it seems mandatory in your data.
gen id= 1 if (char[_n-1] >= char[_n]) | _n ==1
replace id = sum(id) if id==1
replace id = id[_n-1] if missing(id)
fillin id char
drop _fillin
If an individual as only the characteristics A and C and another individual as only the characteristics D and E, this won't work, but it seems impossible to detect with your data.

Delete observations in a panel when identifier is contained in a list of values

I have an unbalanced panel with the panel id member
I would like to delete particular members from the data set (i.e. in every panel they appear), and would like to delete those specific members that appear in a list/vector of values.
If I have the list of values of member (say 1, 3, 10, 17, 173, 928)
I would like a way to drop every observation where the panel id (member) is contained in the list.
The list is ~1500 values long, so rather than manually typing
drop if member == 1
drop if member == 3
drop if member == 10
drop if member == 928
I would like to somehow automate this process.
#Brendan Cox (namesake, not a relative) has the nub of the matter. To expand a bit:
Note first that
drop if inlist(member,1,3,10,17,173,928)
would be an improvement on your code, but both illegal and impractical for a very large number of values: here 1500 or so certainly qualifies as very large.
At some critical point it becomes a much better idea to put the identifiers in a file and merge. For more on the spirit of this, see http://www.stata.com/support/faqs/data-management/selecting-subset-of-observations/
It's not a paradox that you merge here (temporarily making a bigger dataset) even though you want to make a smaller dataset. merge identifies the intersection of the datasets, which is precisely those observations you wish to drop. merge to create unions of datasets merely happens to be the main and most obvious motive for using the command, but there are others.
You do not specify how the list is structured. Please remember to post all details relevant to your problem.
Below two examples.
clear
set more off
*----- case 1 (list in another .dta file) -----
// a hypothetical list
input ///
idcode
1
3
end
list
tempfile mylist
save "`mylist'"
// rest of data
clear
use http://www.stata-press.com/data/r13/union.dta
list if idcode <= 4, sepby(idcode)
merge m:1 idcode using "`mylist'", keep(master)
list if idcode <= 4, sepby(idcode)
*----- case 2 (list in a macro) -----
clear
use http://www.stata-press.com/data/r13/union.dta
// a hypothetical list
local mylist 1, 3
drop if inlist(idcode, `mylist')
list if idcode <= 4, sepby(idcode)
help inlist mentions the following limit:
The number of arguments is between 2 and 255 for
reals and between 2 and 10 for strings.

Issue with ms access 2000, repeating display of same field in query

I was having an issue with ms access 2000 in which I try to enter the same field in a query multiple times and it only displays the field once. As in if I entered the field with the number being (for example) 8150 multiple times, it would only display it once.
This image shows the query.
I've already checked everything on ms access 2000 to try to resolve this issue but I've come up with nothing suitable.
I know your data set is simplified, but looking at your data, inputs, etc, it appears your query is pulling from a single table and repeating results -- so there is no join consideration.
I think the issue is your DISTINCTROW in the query, which is removing all duplicate values.
If you remove the "DISTINCTROW," I believe it may give you what you are expecting. In other words, change this:
SELECT DISTINCTROW Ring.[Ring Number], Ring.[Mounting Weight]
FROM Ring
To this:
SELECT Ring.[Ring Number], Ring.[Mounting Weight]
FROM Ring
For what it's worth, there may also be some strategies to simplifying how this query is run in the future (less dependence on dialog box prompts), but I know you probably want to address the issue at a hand first, so let me know if this doesn't do it.
-- EDIT --
The removal of distinct still applies, but I suddenly see the problem. The query is depicting the logic as "OR" of multiple values. Therefore, repeating the value does not mean multiple rows, it just means you've repeated a true condition.
For example, if I have:
Fruit Count
------ ------
Apple 1
Pear 1
Kiwi 3
and I say select where Fruit is Apple or Apple or Apple or Apple, the query is still only going to list the first row. Once the "Or" condition matches true, short-circuiting kicks in, and no other conditions matter.
That does not sound like what you want.
Here's what I think you need to do:
Get rid of the prompts within the query
Load your options into a separate table -- the repetition can occur here
Change your query to perform an inner join on the new table
New table (named "Selection" for the sake of example):
Entry Ring Number Mounting Weight
----- ----------- ----------------
1 8105 you get the idea...
2 8110
3 8110
4 8110
5 8115
6 8130
7 8130
8 8130
9 8130
10 8150
New Query:
select
Ring.[Ring Number], Ring.[Mounting Weight]
from
Ring
Inner join Selection on Ring.[Ring Number] = Selection.[Ring Number]
This has the added advantage of allowing more (or less) than 10 records