I have two groups of firms, group A and group B, and I have a variable for each firm, call it beta. Using proc rank, if I form 5 portfolios from group A's beta rankings, how can I assign firms from group B to group A's portfolios based on group B beta values, not group B's beta rankings?
Define a format from the high/low beta values for the rankings for group A, and apply that format to the beta values for group b.
Related
I have a Fact Revenue, with 2 dimensions: Customer and Category.
I have the below data:
(In my pbix I have the below visual). There are just 1 or 2 customers that have changed category; so for that specific case, I see:
(This is correct, since the NewCategory has no revenue for the last year).
But, I don't want to see Revenue LYTD as blank; is there a way to display Category, but in fact do a group by Customer?... That way, I would be able to display:
Code is:
Revenue YTD:=CALCULATE ( [Revenue] , DATESYTD('Date'[Date],"31/05") )
Revenue LYTD:=CALCULATE ( [Revenue YTD] , SAMEPERIODLASTYEAR('Date'[Date]) )
I don't think something like that is possible, because logically it doesn't really make much sense.
In your desired outcome how do you know that it will show NewCategory if you don't group by it or specify it in any way? In some flavors of SQL that allow you to do that, it will show you the first category it finds (which in your specific case is OldCategory, but essentially it will be random and based on the order of rows in the table).
I would suggest first creating a mapping table, in which every old category corresponds to the relevant new category. Then join this table to your fact table. Finally, use a new category from the mapping table to group the revenue in the fact table.
I have a table like this showing the id of a member, the beginning and end date of their membership, the days of their membership and the gap between their last membership and current membership period.
for example, member 11101 started their membership on 3/1/95 and paused their membership on 11/01/97. they renewed their membership on 6/1/97 without a gap. the total days of this span is 822+153=975 days
he terminated his membership on 11/1/97 and restarted it on 11/10/04. the gap between these two membership are 11/10/04-11/01/97=2565 days
Im trying to find out the longest spans of a certain member's continuous membership, which is 2160 in this case. I think a window function lag/lead is necessary in SQL. however window function is not supported in sql. how can group these periods based on gap days and calculate the max spans?
thank you for the help!
enter image description here
This question was originally tagged SQL/MySQL/Oracle. This answers the original version of the question.
You can summarize the data for each members for a user. The idea is to sum up the non-zero values of gap (which is rather convenient to have). This defines a group that can be used for aggregation. And, in this case, you can just sum the gap:
select id, sum(span), min(begin_date), max(end_date)
from (select t.*,
sum(gap) over (partition by id order by begin_date) as grp
from t
) t
group by id, grp;
For only the longest per id, you can use window functions again:
select *
from (select id, sum(span), min(begin_date), max(end_date),
row_number() over (partition by id order by sum(span) desc) as seqnum
from (select t.*,
sum(gap) over (partition by id order by begin_date) as grp
from t
) t
group by id, grp
) ig
where seqnum = 1;
I'm trying to select rows in between two values using big query.
Here the table is:
ID Group values
1 A 10I
1 B 20I
1 C 30I
1 D 40I
1 E 50I
1 F 60I
1 G 70I
1 H 80I
1 I 90I
Here I need to select rows from Group C to G.
The code i'm using is:
select * from data
where Group >= 'C' and Group <='G'
The above code gave no results.
Also i tried:
select * from data
where Group between 'C' and 'G'
This also returned no results.
Someone please provide a solution.
This is because "Group" is a reserved word (the GROUP BY): BQ expects you to group something and didn't understand that here it is the name of a column. To make BQ understand just as backslashes:
SELECT *
FROM data
WHERE `Group` BETWEEN "C" AND "G"
I've 2 cols lets say id and values. I want to concatenate values grouped by id col.
for eg.
I've
ID Values
1 a
1 b
2 a
2 b
I need the output as
ID Values
1 a,b
2 a,b
You can use an array_agg followed by an array_join
select id, array_join(array_agg(values),',') from table group by 1
The array_agg will give you an array of all values with the same id, and the array_join will concatenate them into a string. See the docs.
I am running a simple linear regression in SAS. The regression has three different groups of participants as the predictors (with group 1 as the reference), the outcome a continuous social support variable, and five covariates. Three of the covariates are dichotomized (age, sex, & education), one is a three-level nominal variable (marital status), and the last is continuous (it's a chronic disease index).
My question is: Do I need to specify the different types of covariates in the SAS coding somehow?
Would this coding example be correct?:
proc glm data=work.example;
class group age sex education marital education chronic_diseases;
model social_support = group age sex education marital education chronic_diseases;
estimate 'group 1 vs group 2' group -1 1 0;
estimate 'group 1 vs group 3' group -1 0 1;
run;
The class statement tells SAS that you want to consider a variable non-continuous: that is, categorical or binary. It doesn't differentiate between the two, as it will choose the reference based on the first value in ascending order by default unless you specify a reference group.
For example, if you're comparing Apples and Oranges, SAS will use Apples as the reference value. Hey, they're fruit - you can compare fruit to fruit! :)
All model covariates are considered numeric unless specified in a class statement. Since chronic_diseases is continuous, simply remove it from the class statement; otherwise, SAS will look at every single value of chronic_diseases and consider it a level, then compare them all to the lowest level.
proc glm data=work.example;
class group age sex education marital education;
model social_support = group age sex education marital education chronic_diseases;
estimate 'group 1 vs group 2' group -1 1 0;
estimate 'group 1 vs group 3' group -1 0 1;
run;