Stata 17 table - show levels with frequency=0 - stata

I am using the new table command in Stata 17 to create a frequency table of a factor variable using fvfrequency and fvpercent. Some possible levels of the factor have 0 frequency, so are not appearing in the table, but I would like to still show a row for those levels. Is there a way to do this?

Related

in Dax, how do I row match by some categorical column instead of getting a single value when using a numerical variable from another related table

How can I use the values of a variable from a table B in a related table A in a such a way that it can be matched to each row of table A correspondingly?
I need to calculate a ratio as this
sum(A[event_number])/sum(B[client_number]
The 2 variables are from different related table. The relation between the tables are one (A) to many (B).
When I put this ratio on a matrix constructed with variables and measures from table A where the rows are stores, the denominator should be the client number per store but I only get the sum of all clients instead.
For example if a store "ASD" has 5 events it should get divided by 20 which are the clients related to that store and not 500 which is the sum of all clients for all stores.
I have tried using related when calculating the ratio, and allexcept to create a column of number of clients in A but nothing has given the expected result. Please help.

Power BI - Subtract values from same row

I have the following output from two tables.
Item# Desc Sales Rank1 Company Sales Rank2 Rank Diff
1 Wigit1 500 1 ABC 15 32 31
2 Wigit2 300 2 XYZ 80 16 14
Rank1 data is from table A and Rank2 data is from table B. Both tables are tied together with the Item#. I'm trying to correctly get the Rank Diff to calculate from Rank2 - Rank1.
Do this in Power Query with a simple merge and add a Custom Column with the arithmetic. This can all be achieved using the menu and options, no code required. This is the same as in Excel, so here's a walkthrough from Microsoft that goes through all the steps you might need. Once you start using Power Query you won't look back. Good Luck!
if you don't have excess to 'Transform Data'( Power Query new name), then simply go to modelling tab and create a new column
Rank_Diff= TableName[Rank2]-TableName[Rank1]

How to get sum of distinct values in Power BI?

Example, I have the below column where I need to add only the unique values.
number
44
44
55
55
66
66
You can do this fairly simply with a measure.
Distinct Sum = SUMX(DISTINCT(Table1[number]), Table1[number])
The DISTINCT function creates a list of distinct values in the specified column. Then SUMX goes through this list one at a time and adds Table1[number] for each row.
I'm assuming you mean that you'd like the sum of 44+55+66=165.
To me it seems that the best approach is to build a new table using the measure unique = DISTINCT(Table1[number]). You could add it as a measeure in an existing table, but it will most likely cause troubles in your visualizations.
So if you have a table like this:
Then you can go to the Report tab and select Modeling > New Table and insert the formula above.
And then you can easily display the total in a Table or Matrix visualization like this:

DAX way to return summarised data

I hope I'm not missing an easy solution am still getting used to DAX and can't yet find an appropriate logic.
I have a large dataset, >10m rows which I want to test. An identifier column "DocumentNumber" might occur on multiple rows and I want to find where the sum of "Value" over these rows for a given "DocumentNumber" is non-zero.
Tried to use PowerQuery > removed all but these two columns > Group By > DocumentNumber > Sum of Value. However my 32 bit version of Excel appears to run out of memory performing this step Expression.Error: Evaluation ran out of memory and can't continue.
Wrote a DAX measure > Sum of Values and dropped into a pivot table with a view to filtering out the zero values but when I try to drag in the DocumentNumber to rows there are more than a million rows so the table won't render.
Is there a logic I should follow in DAX that would achieve step 2 before bringing it to the pivot table? Can DAX actually create a new table in the data model which is the aggregated and filtered data rather than using a pivot? I believe this is possible in PowerBI but not sure about Excel evironment.

Custom calculation for visualization

I am looking to create a custom calculation for a visualization in Power BI. In particular, I am looking to get a weighted average of my data.
My data set looks something like this:
Cluster Name | Node | Call Name | Errors | Calls
I would like to make a dashboard where I'm giving the percent error over time based on filters on the level of Cluster Name, Node, Call Name, or some combination of these. (The cluster name being the most broad and the call name being the least broad.)
I can easily set up a SQL query that gives me the percent error for each of these categories by doing SUM(Errors)/Sum(Calls) grouped by the category used and this is what I would like to replicate in my visualization.
The reason why I cannot simply calculate the percent error for the broader categories by taking an average of the simpler categories is that not every Call Name has an equal number of Calls. Therefore, I have to use a weighted average or simply recalculate SUM(Errors)/Sum(Calls) for each category selection.
I have tried to accomplish this using a custom column using DAX, but the numbers that the column calculates make no sense. My formula is PercentError = DIVIDE(MyTable[Errors], MyTable[Calls],0)*100, but the calculation seems to give really off numbers. For example, one row has 45 errors and 48 calls, but the percent error is listed as 2630.
Is there a way to do this through the visualization and/or the custom column calculations?
You can do this using a calculated measure rather than a calculated column. The formula would be exactly what you have described in your post
=SUM(Table[Errors])/SUM(Table[Calls])
Format as a % in the Modelling tab and voila.
Put your new measure in the values of a visual like a Matrix and put whatever columns you want to slice and dice this by in the Rows or Columns.