I want to compute multiple new variables for cases that are NOT missing multiple values. For those cases where Var.1 to Var.10 are missing, then I want the computed vars A, B, C to be SYSMIS.
Example code:
DO IF (NOT MISSING(Var.1 to Var.10)).
COMPUTE A=0.
COMPUTE B=0.
COMPUTE C=0.
END IF.
This produces multiple errors:
DO IF - The number of arguments to a function was incorrect.
END IF - The command does not follow an unclosed DO IF command.
I've tried removing periods and adding/removing parentheses to no effect. Thanks for your help.
You could first count the missing values in your multiple set:
count Nmiss=Var.1 to Var.10 (missing).
Now you can use the count in your if statement:
do if Nmiss=0.
...
(or do if Nmiss<10. - depending on your exact goal)
Related
I am trying to recode a variable with an IF statement with 3 x AND conditions within it.
When I run the syntax it doesn't present any errors but the variable has not changed.
Example of Syntax:
IF (((Variable_a =0) AND (Variable_b=0)) AND (Variable_c >0)) Variable_d=9999.
I've tried various combinations of ()s but no joy.
All values in each variable are numerical
Any suggestions of how to overcome this?
EDIT - added an 'execute' command to the end of the code. Unfortunately it still doesn't appear to be work.
I'm trying to keep the numbers in "Inv.No." till 3-digits only having condition that either of the two specific cells are not empty. I am unable to do that after No.10. Below are few of the codes that I've tried with IFS function. Please note that the all cells have been kept to be "Numerical", the first is [(E5) = "00"&1 ]
Codes:
=ifs(OR(I15="",E14=""),"",if(OR(E14>1,E14<9),"00"&(E14+1),"0"&(E14+1)))
=ifs(OR(I11="",E10=""),"",OR(E10>1,E10<9),"00"&(E10+1))
Image of the current ouput
Try using Text instead of the If statement:
=if(E5="","",text(E5,"000"))
Or as an array formula:
=ArrayFormula(if(E5:E="","",text(E5:E,"000")))
Using these two formulas in Google Sheets results in different output results.
The IF result will expand the array across the cells as expected.
The IFS result only displays the first array value.
=IF(1=1,{1,2,3}) RESULT: 1 2 3 (across three cells)
=IFS(1=1,{1,2,3}) RESULT: 1 (in one cell)
Can someone explain why these results differ?
You may think that behaviour of IFS() is similar to IF() and reason of having IFS() is to avoid nesting of multiple IF() but that's not so true. Yes, there are some common baselines however, there is a major difference when it comes to arrays. IFS() in a combination of arrayed output expects arrayed input - that's why you got returned single-cell output instead of arrayed output.
let's say your IF() formula is like:
"converting" it into IFS() will return this (because cell A1 is not array/range):
now let's add a arrayformula (ranged input):
also note this behaviour:
Not at answer to why (IMO off topic) but to get the same result from IFS:
=IFS({1,1,1},{1,2,3})
Can be written:
=IFS({1=1,1=1,1=1},{1,2,3})
I am trying to do a non-linear estimation in Stata where some observations do not need all of the variables. The following is a made up example
nl (v1 = ({alpha=1})^({beta=1}*v2) + ({alpha})^({beta}*v3))
some times there is a value of v3, sometimes there isn't. If it is unneeded in the data, it is coded as missing (although its not missing in the sense the data is lacking, the data is perfect). When v3 is missing, I want Stata to treat the above expression as if the term with the v3 isnt there, so in these cases I would just want it to treat the expression for these observations as:
v1 = ({alpha=1})^({beta=1}*v2)
When I run this, stata says:
starting values invalid or some RHS variables have missing values
I know the starting values are fine,
As you can see, simply recoding the missing values to zero will not work. Because it doesn't zero out the term.
Is there something I can do with a sigma summation notation where it only adds the terms for which there are non-missing values?
-Thanks!
Something like this should work:
cls
sysuse auto, clear
gen nm_rep78 = cond(missing(rep78),1,0)
recode rep78 (.=0), gen(z_rep78)
tab nm_rep78 z_rep78
nl (price = ({alpha=1})^({beta=1}*mpg) + nm_rep78*({alpha})^({beta}*z_rep78))
The idea is that you use an indicator variable to zero out the second term.
There might be a way to get nl to use factor variable notation to simplify this, but I've been testing a new cocktail recipe all afternoon and should not attempt this.
After having worked out a bunch of other errors I'm left with the following
ERROR: P does not have a numeric suffix.
From all the info I've been able to find this happens a lot when using PROC TRANSPOSE, however I'm not using that here (and don't anywhere else in this code).
Data Spillover_HE (rename=(F1=FY F2=BN F3=employeeID F4=grade_subject_ID
F5=AsmtID_agg F6=linkB F7=subgroupID F8=w F9=MGP_SE F10=Residual_SE
F11=Residual_Var F12=mgp_var F13=student_n F14=calcID F15=sumwt F16=MGP
F17=ave_prescore F18=p_imp F19=p_postImp F20=p_sped F21=p_sped_rs
F22=p_sped_se_ss F23=p_sped_st F24=p_sped_tt F25=P-ell F26=p_ed
F27=p_hispanic F28=p_black F29=p_white F30=p_asian F31=p_other
F32=p_blahispmale F33=p_overaundcred F34=p_retained F35=p_transfer
F36=p_top10 F37=p_top5 F38=p_top1 F39=p_bot10 F40=p_bot5 F41=p_bot1
F42=target_population F43=mean_residual_var F44=P_0_5)); run;
Obviously I have a bunch of variables that start with "p". None of them are underlined in the log. I'm using SAS Base, and got the same error in SAS Enterprise Guide.
Not sure what my next move should be. Thanks.
A dash is not a correct character in a variable name.
Replace F25=P-ell into F25=P_ell.
You can use dash to specify a range of variables e.g. rename=(x1-x100=y1-y100). This code renames 100 variables with prefix x to y.