Q:

What can we infer from the different nativity accounts in Matthew and Luke?

The gospels attributed to Matthew and Luke narrate very different stories about the birth of Jesus. Matthew says that Jesus' family was from Bethlehem, that wise men brought gifts to their home, that they escaped to Egypt when Herod the Great ordered to kill all children under the age of three and that they moved to Nazareth because they could not go back to Bethlehem (no census or baby in a manger); Luke says that Jesus' family was from Nazareth, that they went to Bethlehem for the census of Quirinus (at least a decade after Herod the Great was no longer the ruler of Judea), and they went to Jerusalem after 41 days then Nazareth right after (no wise men, guiding star or mass killing).
Since the stories are incompatible, can we conclude that at least one of them was invented? How can we tell which is true, if any?

A:

Uta Ranke-Heinemann says, in Putting Away Childish Things, page 7, that the nativity accounts in the Gospels of Matthew and Luke are, with respect to time, place, and circumstances, a collection of legends. She says (page 11) Luke wants to make the birth of Jesus in Bethlehem plausible by fabricating the story of the census.  But since he handles the facts arbitrarily, the facts themselves refute him. For Matthew, Mary and Joseph do not live in Nazareth: they are in Bethlehem from the outset, so the author has an altogether different problem from Luke's. Matthew's "Jesus of Nazareth" somehow had to arrive in Nazareth from Bethlehem.  This happened, says the Evangelist, so “that what was spoken by the prophets might be fulfilled, 'He shall be called a Nazarene’” ( Matthew 2:3).  
Raymond E. Brown says, in An Introduction to the New Testament, page 114, Luke's infancy narrative is not only massively different from Matthew's, but also in details is virtually irreconcilable with it, for example about Joseph and Mary's home (in Bethlehem in Matthew 2:11 [house]: in Nazareth in Luke 2:4-7, with no home in Bethlehem) and about their travels after the birth of Jesus (to Egypt in Matt 2:14; to Jerusalem and Nazareth in Luke 2:22,39). 
Ian Wilson discusses the discrepancies between the two infancy accounts, in Jesus: The Evidence, and says (page 46) that when Matthew tries to justify Jesus’ apparent divine parentage from Isaiah’s supposed prophecy: ‘The virgin will conceive and give birth to a son’ (Isaiah 7:14), this all too clearly reveals that whoever wrote at least this part of Matthew’s Gospel was no true Jew. And (page 47) he says the problem with Luke is that the first-ever census took place during Quirinius’ governorship, but this did not happen until 6 CE, the first year that Judea came under direct Roman control. Wilson infers that the Luke’s author may have been trying to make it appear that he knew more about Jesus’ birth than he actually did.
These are only a few of the respected New Testament scholars who have critically examined the gospel nativity stories.  Their work can only lead to the inference that the infancy accounts were literary creations written to satisfy early Christians who wanted to know something about the early life of Jesus, although the evangelists had no historical information to work from. The stories are so different because each author was unaware of what the other evangelist was writing.

A:

The simple answer is, of course they are different, they are describing actions that happened on two separate occasions. One narrates from His birth until 40 days later; while the other tells of events that happened around the age of two. First you have to remember that there were no chapter and verse markers in the original Greek; you can’t always assume the books were divided at the correct places. Look at one of the most well-known passages in the Bible: Isaiah 53, almost every Bible teacher starts his study by saying, “Open your Bibles to Isaiah 52 verse 13,” because that is where the train-of-thought starts and continues on until the end of chapter 53. If you just start at the beginning of chapter 53, you will miss some very important prophecy and wisdom. One of the main things that throws people’s timing off in Jesus’ birth and early years is that in Matthew chapter 2 where the translators have rendered verse 1 as “Now when Jesus was born … etc.” it makes it sound like that which is stated next is happening at the same time. But when you look the verse up in the Greek, the word, “when” is not there. 
Gr. transliteration:    de Iēsous gennaō en Bēthleem Ioudaia 
             en hēmera Hērōdēs basileus
Word-for-word trans:     Now Jesus born in Bethlehem Judaea 
                 in days Herod king
Translators inserted two words, where there is only one in the Greek. If Matthew had intended to say “when,” he would have used the Greek – epan, such as where he uses it a few verses later:
And he sent them to Bethlehem,
and said, Go and search diligently for the young child;
and when++ ye have found him,
bring me word again,
that I may come and worship him also.
[Matthew 2:8 KJV]  ++(Greek – epan)
Verse one should be the statement:  
Now Jesus was born in Bethlehem of Judaea
 in the days of Herod the king. (period)
Actually this should be the last verse of chapter one! The Greek – de  translated as “now” is a conjunction (connecting word) that is elsewhere translated as “and”, “then”, “moreover”, etc. which ties it to the previous verse, Matthew 1:25:
Then Joseph being raised from sleep 
did as the angel of the Lord had bidden him, 
and took unto him his wife: 
And knew her not till she had brought forth her firstborn son: 
and he called his name JESUS. 
Now, Jesus was born in Bethlehem of Judaea
 in the days of Herod the king.
[Matthew 1:24-25 & 2:1a]
The Greek – de is used almost 3000 times in the New Testament, translated as over a dozen different words:  but (1,237x), and (934x), now (166x), then (132x), also (18x), yet (16x), yea (13x), so (13x), moreover (13x), nevertheless (11x), for (4x), even (3x), misc (10x), not trans. (300x). The meaning selected seems rather arbitrary; just to connect two thoughts together. The emphasis is on the thoughts, not on the conjunction. Not the kind of word you want to base your whole belief system on. Context is extremely important; when a word has more than one meaning, a translator must make sure that the word he picks does not conflict with the rest of the passage. The New King James version, and several others, read: “Now after Jesus was born…etc.,” apparently trying to fix the previous mistranslation, but they are still adding an extra word where there is not one in the original.
Chapter two should begin the narrative of the wise men’s visit, which occurred two years later:
Behold, there came wise men from the east to Jerusalem, 
Saying, Where is he that is born King of the Jews?
 for we have seen his star in the east, 
and are come to worship him.
[Matthew 2:1b, 2]
How do we know that this was two years later?  One big hint is that in his gospel, Luke uses the Greek – brephos which means, “babe” or “infant”:
And this shall be a sign unto you; 
Ye shall find the babe (Greek – brephos)
wrapped in swaddling clothes, lying in a manger. 
[Luke 2:12 KJV]
…while Matthew uses the Greek – paidion which means, “young child,” in his narrative, 
And he sent them to Bethlehem, and said, 
Go and search diligently for the young child; (Greek – paidion)
and when ye have found him, bring me word again, 
that I may come and worship him also.
 [Matthew 2:8 KJV]
And, as we will see, Herod came right out and asked the wise men, “How long ago did the star appear?” The answer to this question would establish the age of the new king:
Then Herod, when he had privily called the wise men, 
enquired of them diligently what time the star appeared. 
[Matthew 2:7 KJV]
So you can see from the verse below that Herod knew that he was to looking for a two year-old in Bethlehem. But, then Herod used that knowledge to determine that if he wanted to get rid of the new king, he would have to kill all the children, that were two years old in Bethlehem, and just to make sure, he killed all of those that were younger also:
Then Herod, when he saw that he was mocked of the wise men, 
was exceeding wroth, and sent forth, 
and slew all the children that were in Bethlehem, 
and in all the coasts thereof,
 from two years old and under,
 according to the time which he had diligently enquired of the wise men. [Matthew 2:16 KJV]
Once you understand the fact that the wise men visited Jesus two years after His birth, and not in the manger, all the alleged “irreconcilable contradictions” disappear.
Here is a more complete timeline, some of this is from a Messianic-Jewish perspective, and includes a few Jewish celebrations and memorials, that in no way detract from the Christian message; we both use the same bible, and worship the same Messiah Jesus. The dates listed are from the Biblical-Hebrew calendar. The calendar year starts on the Passover month. Tishri is the seventh month. That coincides with our common September-October time of year.
Day 1 - Tishri 14 Daytime
Mary and Joseph arrive in Bethlehem from their home in Nazareth to register.
All went to be taxed, every one into his own city. 
And Joseph also went up from Galilee, 
out of the city of Nazareth, into Judaea, unto the city of David,
 called Bethlehem; (as he was of the house and lineage of David:)
 [Luke 2:3,4]
Day 1 - Tishri 15 Evening 
(a new day starts at 6:00 in the evening for the Jews)
Jesus is born in the manger in a booth (tabernacle) that Joseph has built, fulfilling the Feast of Tabernacles.
And so it was, that, while they were there,
the days were accomplished that she should be delivered.
And she brought forth her firstborn son,
and wrapped him in swaddling clothes, and laid him in a manger;
because there was no room for them in the inn.
[Luke 2:6,7]
Now, ++ Jesus was born in Bethlehem of Judaea
 in the days of Herod the king.
[Matthew 2:1a]
(++ The word “when” is not in the Greek)
Day 2 - Tishri 15 Night to Early morn.
Shepherds see angels and come and find Jesus.     
And there were in the same country shepherds abiding in the field,
 keeping watch over their flock by night . . .
And it came to pass, as the angels were gone away from them into heaven, 
the shepherds said one to another, 
Let us now go even unto Bethlehem, 
and see this thing which is come to pass, 
which the Lord hath made known unto us. 
[Luke 2:13, 15]
Day 8  - Tishri 22
Jewish celebration of Simchath Torah - Rejoicing over the Law  -  Family goes to a local Bethlehem Rabbi for Jesus' circumcision (A symbol of obedience to the Law). 
And when eight days were accomplished for the circumcising of the child, 
his name was called Yehu’shua (Jesus), 
which was so named of the angel before he was conceived in the womb. 
[Luke 2:21]
Day 40 – Heshvan 25
On the 40th day (7 days plus 33 days = 40 days) they are in Jerusalem for Jesus’ presentation in the temple:
Speak unto the children of Israel, saying,
 If a woman have conceived seed, and born a man child:
 then she shall be unclean seven days; 
according to the days of the separation for her infirmity shall she be unclean. And in the eighth day the flesh of his foreskin shall be circumcised.
And she shall then continue in the blood of her purifying three and thirty days; she shall touch no hallowed thing, 
nor come into the sanctuary,
 until the days of her purifying be fulfilled. 
[Leviticus 12:2-4 KJV]
They offer "a pair of turtledoves or two young pigeons" which is an alternate offering which can only be made by a poor family that cannot afford to offer a lamb:
And if she be not able to bring a lamb, 
then she shall bring two turtledoves, or two young pigeons;
 the one for the burnt offering, and the other for a sin offering: 
and the priest shall make an atonement for her,
 and she shall be clean. 
[Leviticus 12:8 KJV]
And when the days of her purification
 according to the law of Moses were accomplished, 
they brought him to Jerusalem, to present him to the Lord;
 (As it is written in the law of the Lord, 
every male that openeth the womb shall be called holy to the Lord;) 
And to offer a sacrifice according to that which is said in the law of the Lord, A pair of turtledoves, or two young pigeons.
[Luke 2:22,23,24] [Leviticus 12:1-8]
If they had already received the gold from the wise men, they could have easily afforded a lamb. But they do not have it yet.
After day 40
Later, back home to Nazareth. 
When they had performed all things according to the law of the Lord,
 they returned to Galilee, to their own city Nazareth. 
[Luke 2:39]
Sometime before the second year of Jesus life, they move to Bethlehem. After all, it is the city of their ancestors; there are probably relatives there. Or they could be feeling guilty for not living on the land that would be their portion (inheritance) as descendants of King David. Or maybe because all the prophecies at the temple made them think that, maybe, they were supposed to stay in Bethlehem, since that is where the Scriptures say that the Messiah was to be born. For whatever the reason, here they are in Bethlehem two years later, it is a perfectly logical occurrence. Joseph and Mary didn’t know that the wise men were coming; but God did! He made sure that they were there in Bethlehem with Jesus when the Magi arrived. God is the One who makes sure that all prophecies are fulfilled. In the same way that God compelled Caesar to require a census, which drew Mary and Joseph to Bethlehem, the first time; God drew them back to Bethlehem to receive the wise men.
Year 2 
Wise men (not 3 kings) came to Jerusalem from the East (possibly Babylon, 900 miles away, that could be why it took two years to get there). The wise men follow star to Jerusalem and then to a house in Bethlehem (not a stable). They worship the young child++, Jesus, offer their gifts and then leave. Family flees to Egypt after a warning by an angel in a dream. Herod kills all babies in Bethlehem, 2 years old and under, according to the time determined from the wise men. [Matthew 2:7,11,13,16] 
 (++Matthew uses the Greek Paidion = young child vs. Luke’s brephos = babe, infant)
Shortly after Jesus' family journeys to Egypt, Herod dies, and his three sons take over the kingdom. The gold from the wise men probably came in very handy, so that this poor family could live in a foreign country for several years. Some time before 6 a.d. the family returns to Israel. They go back to Nazareth of Galilee because they are afraid to go back to their new house in Bethlehem because Herod's son, Archelaus, is reigning in Judea. (The Roman government deposed Archelaus in 6 a.d. because he was too oppressive even by Roman standards.) 
But when Herod was dead, behold, 
an angel of the Lord appeareth in a dream to Joseph in Egypt, 
Saying, Arise, and take the young child and his mother, 
and go into the land of Israel: 
for they are dead which sought the young child's life. 
And he arose, and took the young child and his mother, 
and came into the land of Israel.
But when he heard that Archelaus did reign in Judaea 
in the room of his father Herod, he was afraid to go thither: 
notwithstanding, being warned of God in a dream,
 he turned aside into the parts of Galilee:
 And he came and dwelt in a city called Nazareth: 
that it might be fulfilled which was spoken by the prophets,
 He shall be called a Nazarene.
 [Matthew 2:19-23 KJV]
They are still in Nazareth when Jesus is 12. [Luke 2:41-52] There is no reliable record of the time between ages 12 and about thirty, when He began His ministry.
In order for the wolf-in-sheep’s-clothing to convince his unsuspecting listeners that there is a contradiction, they have to make many assumptions that are nowhere stated nor implied in the Bible:
The passage in Matthew above:
…Does not say that they always lived in Bethlehem;
…Does not say that they had never lived in Nazareth before.
…Does not say that the wise men visited Jesus in a manger or a stable.
…Does not say that the wise men visited Jesus while He was an infant. 
(Matthew specifically used the Greek word Paidion which means young child, not baby.) 
When you study your Bible carefully and prayerfully, the Holy Spirit leads you to connect-the-dots, so to speak, to learn more of the truth of God’s Word. I’ve met many people who told me that they read the Bible from cover to cover and just don’t understand it. I have read the Bible about 30 times, in different versions, and am still learning new things. 
Read your Bible daily; the truth is there. Pray for wisdom, for discernment and for Jesus to open your spiritual eyes. Beware, there are people out there, some even claiming to be Christians (wolves–in-sheep’s-clothing), that will try to come between you and the belief that the Bible is the Word of God. Don’t let them. I used to think that people, who claimed that there is a contradiction between the two gospel narratives of Jesus birth and early years, were just ignorant. Well, there may be a few that are naïve, but most of the ones that I have met have an ulterior motive. I’ve had many discussions, on this subject, with some very intelligent gentlemen, who seemed to agree, to my face, that the timetable makes sense, and thank me for setting them straight. But the very next time I see them, they are holding up this, or some other contrived contradiction, to an unsuspecting audience, trying to shame them into doubting their Bibles because of “all” the so-called contradictions. There is none so blind as the one who refuses to see! I am sure that most of you have heard of C.S. Lewis, Josh McDowell and Lee Strobel; they all used to be atheists or agnostics, who set out, independently, to find all the errors and contradictions that they could find in the Bible, to prove to those “unsophisticated Christians” how unreliable it is. They ended up becoming some of the Bible’s strongest defenders. There is power in the Word of God; don’t let it just sit on the shelf! It is your most powerful spiritual weapon; don’t leave home without it – don’t even get out of bed without it! 
If you are not reading your Bible daily; you are reading it weakly!
There is nothing the devil fears more than a faithful man who reads his Bible; believes it, and prays to God Almighty in the Name of Jesus Christ – Be That Man!
God bless you all!

A:

Since the stories are incompatible, can we conclude that at least one of them was invented? How can we tell which is true, if any?
I would like to challenge the assumption that the the two narratives of the birth of Jesus are incompatible.  
Roman Catholic scholar Raymond Brown writes: 

This leads us to the observation that the two narratives are not only
  different—they are contrary to each other in a number of details.
  According to Luke 1:26 and 2:39 Mary lives in Nazareth, and so the
  census of Augustus is invoked to explain how the child was born in
  Bethlehem, away from home. In Matthew there is no hint of a coming to
  Bethlehem, for Joseph and Mary are in a house at Bethlehem where
  seemingly Jesus was born (2:11). The only journey that Matthew has to
  explain is why the family went to Nazareth when they came from Egypt
  instead of returning to their native Bethlehem (2:22-23). A second
  difficulty is that Luke tells us that the family returned peaceably to
  Nazareth after the birth at Bethlehem (2:22,39); this is
  irreconcilable with Matthew's implication (2:16) that the child was
  almost two years old when the family fled from Bethlehem to Egypt and
  even older when the family came back from Egypt and moved to Nazareth.
  Of the options mentioned before we made the detailed comparison of the
  two narratives, one must be ruled out, i.e., that both accounts are
  completely historical. [Brown, Birth of the Messiah, p.46]

However breaking this paragraph down and examining point by point we soon realize that these alleged contradictions are not actually a contradiction, and as this paragraph lays out similar objections as the question our examination of it will (I trust) answer the question raised. 
What is a contradiction
We need to begin by defining the contradiction, a contradiction is defined as:

1:      act or an instance of contradicting   2 a: a proposition,
  statement, or phrase that asserts or implies both the truth and
  falsity of something
      b: a statement or phrase whose parts contradict each other 〈a round square is a contradiction in terms   3 a: logical incongruity
      b: a situation in which inherent factors, actions, or propositions are inconsistent or contrary to one another1

Contradictory is defined as

a proposition so related to another that if either of the two is true
  the other is false and if either is false the other must be true2

So, for the accounts of the birth of Jesus in Luke and Matthew to be contradictory we need to find states in those two accounts that cannot possibly be reconciled one to another. 
With that definition in mind let's begin the examination of the accounts of the birth of Jesus in relation to the points raised in the question as explained by Brown in the quote above. 
1. Where Mary and Joseph live
Brown states: 

According to Luke 1:26 and 2:39 Mary lives in Nazareth, and so the
  census of Augustus is invoked to explain how the child was born in
  Bethlehem, away from home. In Matthew there is no hint of a coming to
  Bethlehem, for Joseph and Mary are in a house at Bethlehem where
  seemingly Jesus was born (2:11).

Luke 1:26 says:

Now in the sixth month the angel Gabriel was sent by God to a city of
  Galilee named Nazareth, (Luk 1:26 NKJ)

Notice that it is clear from Luk 1:31 that Mary has not yet conceived the child that is to be born. This puts this text at least 9 months prior to the birth account. 
Considering Matt 2:11 we read: 

And when they had come into the house, they saw the young Child with
  Mary His mother, and fell down and worshiped Him. And when they had
  opened their treasures, they presented gifts to Him: gold,
  frankincense, and myrrh. (Mat 2:11 NKJ)

This is a reference to the visit of the magi from the east, and considering that Herod determined from them when they first saw the star (2:7) and based upon that information he decided to kill every child aged two or under (2:16) it is entirely possible that at least two years had elapsed between these two texts. 
Now, if Mary and Joseph had decided to stay in Bethlehem after the birth of Jesus we would not expect them still be in the place where the animals lived. 
Why might Mary and Joseph have decided to settle in Bethlehem? 
Whilst this is purely conjecture, it does seem that Joseph and Mary were aware of who this child was (compare Matt 1:19-23 & Luke 1:31-35) and considering the apparently well known prophecy of Micah 5:2 maybe the thought they should settle in Bethlehem because that is where the Messiah was supposed to come from. 
What about Luke 2:39? 

Luke 2:39 So when they had performed all things according to the law
  of the Lord, they returned to Galilee, to their own city, Nazareth.

Here it seems Brown assumes the return was immediately after the rituals were performed, but is that sound exegesis or is he reading something into the text? More conservative scholarship seems to have no trouble inserting a temporal space between Luke 2:38 and Luke 2:39. 

Luke says nothing about the visit to Egypt, which according to Mt.
  2:13ff. preceded the settlement in Nazareth (cf. Lagrange,
  91f.).3

Or

They returned to Galilee to their own town of Nazareth. With this
  comment Luke prepared his readers for the following account in
  2:41–52. Luke did not mention a visit to Egypt as we find in Matt
  2:13–22, but such a visit would have to be placed between Luke 2:38
  and 2:39.4

So, is this a contradiction? 
In this writers opinion the answer is 'no'. Luke records where Mary and Joseph were living before the birth of Jesus and Matthew records where they were living after the birth of Jesus. 6 years I lived in a different city to where I live now. If someone was writing a biography of my life it would not be a contradiction for them to write that I was in Leeds when they refer to events of my life then and to say I am was in Cambridgeshire when they refer to my life now. For this to be considered a contradiction there would actually need to be a clear statement in Matthew's Gospel that makes it plain that Mary and Joseph lived in Bethlehem prior to the birth of Jesus and there is no such statement.       
2) The Journey to Egypt
It is not possible to compare the accounts of the journey to Egypt because Matthew is the only Gospel that records it. Luke doesn't mention it. Luke mentions only that the family returned to Nazerath, he doesn't provide any detail of that journey, either in regards to when it began, where they set off from, where they went on the way (or out of the way) and how long the journey took. Notice that brown states that "Luke tells us that the family returned peaceably to Nazareth after the birth at Bethlehem (2:22,39)." but he does not explain where he gets the impression that the return was 'peaceable' from? 
On this occasion it appears that he is concluding that just because Luke doesn't mention somethbing that Matthew does it must be a contradiction, however that doesn't fit with the dictionary definition of a contradiction. There are any number of reasons why one author might include something that another does not, either the one author might be ware of events that the other isn't, or one author might see a relevance to those events that the other doesn't and so include them whilst another skips past them. Pick two or three biographies of any person and you will find this sort of thing happening, authors focusing on different events.  
Concluding thoughts
Historical critical scholars tend to read their assumptions into the text that contradictions are likely, whereas more conservative scholarship will look at the texts and believe that there are ways that apparent contradictions can be reconciled (they also are reading their assumptions into the text). That is to say we need to understand the presumptions of any scholar before we rightly evaluate there work. To rightly evaluate the work of any scholar we need to compare opposing opinions and reason through the matter for ourselves. 
On this occasion and in regards to the birth narratives there are no genuine contradictions only silences in one or the other narratives. Nothing in Matthew's gospel precludes Mary and Joseph living in Nazareth prior to the birth of Jesus and nothing in Luke's gospel absolutely precludes Mary and Joseph first settling in Bethlehem, then fleeing to Egypt before returning and settling again in Nazareth.         

Notes
1 Mish, F. C. (2003). Preface. Merriam-Webster’s collegiate dictionary. (Eleventh ed.). Springfield, MA: Merriam-Webster, Inc.
2 Mish, F. C. (2003). Preface. Merriam-Webster’s collegiate dictionary. (Eleventh ed.). Springfield, MA: Merriam-Webster, Inc.
3 Marshall, I. H. (1978). The Gospel of Luke: a commentary on the Greek text (p. 125). Exeter: Paternoster Press.  
4Stein, R. H. (1992). Luke (Vol. 24, p. 118). Nashville: Broadman & Holman Publishers.

