gnuplot time axis from two different columns - time

I'm trying to plot some data from a four columns file. The first one is the numbre of data the second one is the year the third one are months and the final one are values of temperature. The thing is that I woul like that my x axis takes a date from the second and the third columns.
The text file look like this:
1 1990 2 265.78945923
2 1990 3 260.53842163
3 1990 4 265.00366211
4 1990 5 277.61206055
5 1990 6 284.72595215
6 1990 7 291.54879761
7 1990 8 293.61392212
8 1990 9 288.47149658
9 1990 10 284.55172729
12 1991 1 285.98762388
13 1991 2 283.47484293
I'm using a code like this:
set xdata time
set timefmt '%Y %m'
plot 'datafile' u 2:4
But it doesn't work. I woul like to have on my x axis the year and the months.
All help appreciated! Thanks

Related

DISTINCTCOUNT function resulting in unwanted aggregation; how to fix it

I have a list of shopping centers that are marked by different age groups with calculated age for the next 10 years.
I am using a rotating card visual that will respond to the year slicer, and I would like the DISTINCTCOUNT function output is set to default to the first year (if I set it to first year using filter, the visual will display Blank for any other years).
Table:
Center Year Age Age Grouping
A 2023 0 0-5
A 2024 1 0-5
A 2025 2 0-5
A 2026 3 0-5
A 2027 4 0-5
A 2028 5 0-5
A 2029 6 06-10
A 2030 7 06-10
A 2031 8 06-10
A 2032 9 06-10
A 2033 10 06-10
B 2023 1 0-5
B 2024 2 0-5
B 2025 3 0-5
B 2026 4 0-5
B 2027 5 0-5
B 2028 6 06-10
B 2029 7 06-10
B 2030 8 06-10
B 2031 9 06-10
B 2032 10 06-10
B 2033 11 11-15
The DAX I wrote for calculated measures are:
Total Center = DISTINCTCOUNT(Center[Center])
Centers 0-5 Years Old = CALCULATE(DISTINCTCOUNT(Center[Center]),Center[Age Grouping] = "0-5")
Centers 6-10 Years Old = CALCULATE(DISTINCTCOUNT(Center[Center]),Center[Age Grouping] = "06-10")
I did not list all data points here because the list goes on and they follow the same pattern. I used DISTINCTCOUNT for all measures but for some reasons, only calculated measure [Total Center] and [Centers 0-5 Years Old] showed up correctly without aggregation; the rest of the measures (e.g. [Centers 6-10 Years Old]) showed up aggregated for all 10 years by default. I attached an image of the metrics below:
This is effecting my rotating card visual that by default it shows Total Center as 211, Centers 0-5 Years Old as 114, Centers 6-10 Years Old as 150 (aggregated), and rest are all aggregated.
I don't know why they are displaying differently when the DAX I used are all the same. There is no filter set on visuals or on the table.
Any advice will be much appreciated.
I have tried changing it from
Centers 6-10 Years Old = CALCULATE(DISTINCTCOUNT(Center[Center]),Center[Age Grouping] = "06-10")
to
Centers 6-10 Years Old = CALCULATE(DISTINCTCOUNT(Center[Center]),FILTER(Center,Center[Age Grouping] = "06-10"))
but nothing have changed.

PowerBI compare two columns in matrix

I am pretty new to PowerBI and cannot figure out a way to compare two values in two columns. All I need is a columns that says True or False. This would be pretty easy in Excel but I am sure there is a way in PowerBI as well?
My data looks like this:
Number
Type
Size
PO1
5
10
PO1
6
12
PO2
5
09
PO2
6
10
PO3
5
10
PO3
6
10
Which I organise to look like this in a matrix (not exactly this formatting but I don't know how to show this, but it's a matrix):
Number
Type 5
Size
Type 6
Size
PO1
5
10
6
12
PO2
5
09
6
10
PO3
5
10
6
10
And I want to know:
Number
Type 5
Size
Type 6
Size
Same size
PO1
5
10
6
12
False
PO2
5
09
6
10
False
PO3
5
10
6
10
True
You could solve this with a calculated table like:
Comparison =
SUMMARIZE(
'Table',
'Table'[Number],
"Same size", MIN('Table'[Size]) = MAX('Table'[Size])
)
which will look like this in a table visual:
What I did was Transform the data as follows:
Number as index column
Min size as 'input'
Max size as 'output'
New column comparing input and output
Save and Run

How to create means in panel data for specific years?

I need help in a particular issue with Stata. I have a panel dataset by id year from 1996 to 2018.
The panel data is a combination of world countries and regions, yearly observations, for 7 different crops, area cultivated.
I would like to create a mean around years 2000, 2010 and 2018, so that mean(year2000)= mean of (1999+2000+2001), mean(year2010)=mean from (2009+2010+2011) and mean(year2018)= mean from (2016+2017+2018) for every crop from my 7 crops selection.
Then the problem is even more complicated when I need to combine some countries to form sub-regions: say I need the sub-region RUS1 = Russia + Ukraine. How can I create another variable that shows the total from crop1 between crop1 area cultivated in Russia + crop1 area cultivated in Ukraine on yearly basis. Meaning another variable that shows these sums for each year using the above means.
I've tried with by id year: egen area_rus1=total(area) if area=="Russia" & area=="Ukraine"
but nothing works.
The names of area being strings I used encode (area), gen (area2) and automatically Stata generates a number.
In order to create a panel dataset i've used gen id=area2+itemcode
The panel data looks like this after sort year
Please be aware that the period is 1996-2018. The example above shows only year 1996.
This didn't get much of a response, for several reasons:
You didn't show very much code.
You didn't show data in a form that is especially useful. An image can't be copied and pasted easily into someone's Stata to allow experiment. In fact your image shows variables that are irrelevant and variables that are different versions of each other and so is much more complicated than we need.
You escalated the question to ask the most complicated version of what you want to know.
There is a problem you should have explained better. area is string and so totals can't be calculated at all and area2 is just arbitrary integers so totals can be calculated but don't make sense. "nothing works" is not informative as a problem report. The only totals that make sense to me are totals of value.
You need to simplify your problem first and then build up.
The essence seems to be as follows:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str2 country str6 item float year str1 region float value
"A" "barley" 1999 "X" 1
"B" "barley" 1999 "X" 2
"C" "barley" 1999 "Y" 3
"A" "barley" 2000 "X" 4
"B" "barley" 2000 "X" 5
"C" "barley" 2000 "Y" 6
"A" "barley" 2001 "X" 7
"B" "barley" 2001 "X" 8
"C" "barley" 2001 "Y" 9
end
* means by countries: similar variables for other periods
egen mean_9901_c = mean(cond(inrange(year, 1999, 2001), value, .)), by(country item)
* aggregation to regions, but ensure that you don't double count
egen value_region = total(value), by(region item year)
egen tag = tag(region item year)
* means by regions: similar variables for other periods
egen mean_9901_r = mean(cond(tag == 1 & inrange(year, 1999, 2001), value_region, .)), by(region item)
list, sepby(year)
+---------------------------------------------------------------------------------+
| country item year region value mean_9~c value_~n tag mean_9~r |
|---------------------------------------------------------------------------------|
1. | A barley 1999 X 1 4 3 1 9 |
2. | B barley 1999 X 2 5 3 0 9 |
3. | C barley 1999 Y 3 6 3 1 6 |
|---------------------------------------------------------------------------------|
4. | A barley 2000 X 4 4 9 1 9 |
5. | B barley 2000 X 5 5 9 0 9 |
6. | C barley 2000 Y 6 6 6 1 6 |
|---------------------------------------------------------------------------------|
7. | A barley 2001 X 7 4 15 1 9 |
8. | B barley 2001 X 8 5 15 0 9 |
9. | C barley 2001 Y 9 6 9 1 6 |
+---------------------------------------------------------------------------------+
The example shows just one item, but the code should work for several.
The example shows fake data for just three years, but means for other periods can be constructed similarly.
Results are repeated for all observations to which they apply. To see or use results just once, use if. For example the means over 1999 to 2001 are shown for each of those years (and others) but if year == 1999 would be a way to see results just once.
See also help collapse, help egen for its tag() function and this paper.
What was wrong with your code
Your problems start with
if area=="Russia" & area=="Ukraine"
which selects observations for which it is true that area is both "Russia" and "Ukraine" in the same observation, which is impossible. You need the | (or) operator there, not the & operator, or to approach the problem in another way.
The prefix id is wrong too. Using by id: enforces separate calculations for different values of id and is going to make the combinations of identifiers impossible.

TiBCO Spotfire - How to Calculate only the last 3 columns in a Data - see descr

Week Sales
1 100
2 250
3 350
4 145
5 987
6 26
7 32
8 156
I wanted to calculate the sales only for the last 3 weeks so the total will be 156+32+26.
If new weeks are added it should automatically calculate only the data from the last 3 rows.
Tried this formula but it is returning an incorrect sum
sum(sales) over (lastperiod(3(week))
https://i.stack.imgur.com/6Y7h7.jpg
If you want only the last 3 weeks sum in calculated column you can use a simple if calculation.
If([week]>(Max([week]) - 3),Sum([sales]),0)
If you need 3 weeks calculation throughout table use below one.
sum([sales]) OVER (LastPeriods(3,[week]))

Determining which Sunday in Ruby

Using Ruby how can you determine if the coming Sunday is the first, second or third Sunday of the month?
#ElYusubov - is close, but not quite right.
As a starting point, the division must be by seven (number of days in a week). But time.day gives a day-of-the-month from 1 to 31, so first you need to subtract one before the division and add one after. The first eight days of any month give...
Day number (Day# - 1) / 7 Week#
---------- -------------- -----
1 0.0 1
2 0.14 1
3 0.29 1
4 0.43 1
5 0.57 1
6 0.71 1
7 0.86 1
8 1 2
Whichever day-of-the-week time.day gives, that week# indicates whether it's the first, second etc of that day-of-the-week. But you want the coming Sunday.
wday gives a weekday - 0 to 6, with 0 meaning Sunday. So how many days are there to the coming Sunday? Well, that depends on your definition of "Coming", but if you exclude today==Sunday, you basically subtract todays weekday from 7.
Weekday today Days until next Sunday
------------- ----------------------
0 (Sun) 7
1 (Mon) 6
2 (Tue) 5
3 (Wed) 4
4 (Thu) 3
5 (Fri) 2
6 (Sat) 1
If you allow the "coming" Sunday to be today, then you do the same thing but replace seven with zero. You can either do a conditional check, or use the modulo/remainder operator.
Anyway, once you know how many days ahead the coming Sunday is, you can calculate the date value for that (add those days to todays date) and then determine the week number in the month for that date instead of today using the first method (subtract 1, divide by seven, add 1).
Relevant vocabulary...
Date.wday 0 to 6 (0 = sunday)
Date.day 1 to 31
I won't try to provide the code because I don't know Ruby.

Resources