Can the Identity Map be a repeated composition one other function? Consider the mapping $f:x\to\frac{1}{x}, (x\ne0)$. It is trivial to see that $f(f(x))=x$.
My question is whether or not there exists a continuous map $g$ such that $g(g(g(x)))\equiv g^{3}(x)=x$? Furthermore, is there a way to find out if there is such a function that $g^{p}(x)=x$ for a prime $p$?  
Edit: I realise I was a little unclear - I meant to specify that it was apart from the identity map. The other 'condition' I wanted to impose isn't very precise; I was hoping for a function that didn't seem defined for the purpose. However, the ones that are work perfectly well and they certainly answer the question.
 A: The function $$f(x) = {1\over 1-x}$$ has $f^3(x) = x$ for all $x$ where $f^3(x)$ is defined. (All reals except for 0 and 1.)
Other than the identity, there is no continuous function $\Bbb R\to \Bbb R$ having $f^3(x) = x$ for all $x$, by Sharkovskii's theorem.
A: Consider the function $f:\mathbb R\to\mathbb R$ such that $f(i)=i+1$ for all $i\in\{1,\dots,p-1\}$, $f(p)=1$ and $f(x)=x$ for all $x\in\mathbb R\setminus\{1,\dots,p\}$.
A: If you don’t impose any other conditions on $g$, it’s certainly possible. For $n\in\Bbb Z$ let $I_n=[n,n+1)$, and define 
$$g:\Bbb R\to\Bbb R:x\mapsto\begin{cases}x+1,&\text{if }x\in I_n\text{ and }3\not\mid n\\
x-2,&\text{if }n\in I_n\text{ and }3\mid n\;.
\end{cases}$$
This map translates $I_{3k+1}$ to $I_{3k+2}$, $I_{3k+2}$ to $I_{3k+3}$, and $I_{3k+3}$ back down to $I_{3k+1}$; it fixes no points of $\Bbb R$.
This generalizes: you can replace $3$ by any integer $m\ge 2$.
A: Consider the class of Möbius transformations: $$f(x) = {ax+b\over cx+d}$$ for some constants $a,b,c,d$. If we represent Möbius transformation $f$ by its matrix of coefficients: $$\hat f =  \pmatrix{ a&b \\  c&d }$$ then it turns out that to compose two Möbius transformations $f$ and $g$ we just multiply their corresponding matrices.
In particular, if $f$ is a Möbius transformation with matrix $\hat f$, then $f(f(f(x)))$ is also a Möbius transformation, with matrix ${\hat f}{}^3$.
So it suffices to find a $2\times 2$ matrix $M$ with $M^3 = I$.  There are numerous examples, but one such is  $$\def\ang{{\frac{2\pi}3}}\pmatrix{\cos\ang & \sin\ang \\ -\sin\ang & \cos\ang} = \pmatrix{-\frac12 & \frac{\sqrt3}2 \\ -\frac{\sqrt3}2 & -\frac12 }.$$ This is just the matrix for the linear transformation of the plane that rotates the plane by a one-third turn about the origin.
So the corresponding Möbius transformation with period 3 is $$f(x) = {x-\sqrt 3\over x\sqrt3 + 1}.$$
By replacing $2\pi\over 3$ with $2\pi\over n$, you can construct a function with any period you want.  
Note that you are not restricted to $M$ with $M^3 = I$.  Since $I$ and $kI$ are the same when considered as Möbius transformation, $M^3 = kI$ will work for any $k$.
A: If there exists some continuous function $g(x)$ ,more necessary it must be continuously differentiable, such that 1.$g(g(g(x)))=x$ , then it is easy to see 
$g'(g(g(x)))g'(g(x))g'(x)=1$. 
Say, $g(g(x))=x_2$ and $g(x)=x_1$ .
See, these $x,x_1,x_2$  creates a triplet in a cycle. Meaning, 
$g(x)=x, g(x_1)=x_2, g(x_2)=x$. So, they are self sustained. 
So, $g'(x)g'(x_1)g'(x_2)=1$
Now, if the function has some(change in direction) stationary point at some point, say $a, g'(a)=0$. Then $g'(a)g'(a_1)g'(a_2)$ never can be equal to 1, which is required. So, the function must be strictly increasing(It can't be strictly decreasing because then,  all of $g'(x),g'(x_1),g'(x_2)$ would be negative. So, there product cannot be $1$). 
Now,  if for some triplet $x,x_1,x_2$, as the function is strictly increasing 
Then,
 1. $x>x_1>x_2$ can't happen. 
 2. $x_1>x>x_2$ can't happen.
 3. $x_2>x_1>x$ can't happen. As they are cyclic.
So, the only way left is all are equal, means $g(x)=x$.
But, I can strictly say these only for continuously differentiable function.
Following this method, we can easily show that, for all odd numbers $m$, $g^{m}(x)=x,\Rightarrow g(x)=x$. Obviously, the function is differentiable everywhere and it's derivative is continuous.
